Using a Shared Library3:55 with Heath Hodgert
Now that we've seen our options for sharing code across platforms, let's use the shared library in our project to eliminate code duplication.
So, we have walked through both Android and iOS, but we have not shared any code. 0:00 We wrote the same code in both platforms to calculate the number of pizzas. 0:07 So let's start by creating a service to do the calculations. 0:12 In the shared project, create a pizza calculation service, and 0:16 add a Calculate method. 0:20 The Calculate method uses a string as a parameter and returns a string. 0:41 So we can move the int parsing calculation and response into this method. 0:48 We could also modify it to return a more informative response. 0:53 Now we'll go back to the Android project. 1:43 In the main activity, new up a pizzaCalculatorService, and 1:48 add the calculate to the click event delegate. 1:52 In the iOS project, the ViewController has a similar event handler for 2:58 TouchUpInside, which can also be changed to use the pizzaCalculatorService. 3:02
You need to sign up for Treehouse in order to download course files.Sign up