Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
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.
We wrote the same code in both platforms to calculate the number of pizzas.
So let's start by creating a service to do the calculations.
In the shared project, create a pizza calculation service, and
add a Calculate method.
The Calculate method uses a string as a parameter and returns a string.
So we can move the int parsing calculation and response into this method.
We could also modify it to return a more informative response.
Now we'll go back to the Android project.
In the main activity, new up a pizzaCalculatorService, and
add the calculate to the click event delegate.
In the iOS project, the ViewController has a similar event handler for
TouchUpInside, which can also be changed to use the pizzaCalculatorService.
You need to sign up for Treehouse in order to download course files.Sign up