A Portable Class Library (PCL) is a C# library project that can be supported on multiple platforms including iOS, Android, Windows, Windows Store apps, Windows Phone, Silverlight, and Xbox 360. PCLs have been an effort by Microsoft to simplify development across different versions of the .NET framework. Xamarin has also added support for iOS and Android in the newer versions of their products. Many popular cross-platform frameworks and open source libraries are starting to develop PCL versions such as Json.NET and MVVMCross.
Let's set up a solution using PCLs. Before starting, make sure you at least have Mono 3.2.1 installed (look under Xamarin Studio | About Xamarin Studio | Show Details). At the time of writing this book, one could easily switch to the beta channel in Xamarin Studio to update to the version supporting PCLs.
Let's begin setting up our portable class library:
ProductSearch.Core
, and name the solution ProductSearch
.Product
, ProductRepository
, and ProductViewModel
classes to the project used earlier in this chapter. You will need to add using System.Threading.Tasks;
and using System.Linq;
where needed.ProductSearch.iOS
.ProductSearch.Droid
.Each solution type has their distinct advantages and disadvantages. PCLs are generally better, but there are certain cases where they can't be used. For example, if you were using a library such as MonoGame, which is a different library for each platform, you would be much better off using file linking or cloned project files. Similar issues would arise if you needed to use a preprocessor statement such as #if IPHONE
or a native library such as the Facebook SDK on iOS or Android.
18.224.32.86