When I design a project in Xamarin.Forms, it allows you to choose between:
Shared Project and PCL.
What's the difference between the two? What are the advantages and disadvantages?
When I design a project in Xamarin.Forms, it allows you to choose between:
Shared Project and PCL.
What's the difference between the two? What are the advantages and disadvantages?
Shared projects have a concept very similar to shared files and folders. Both projects, Android, IOS and Winphone, will have access to the same folders and files, and any changes made to one of the projects will reflect directly on the others.
In this type of project it is very common to find many compilation directives, to execute platform-specific resources:
#if Android
// Escreva um código utilizando um recurso do android
#endif
PCL (Portable Class Library) projects, as the name implies, are projects that allow the creation of compatible codes between target platforms. Once you start creating this type of project the IDE itself will ask you which platforms you will meet with your PCL, and then load the necessary, compatible assemblies between them.
Because it is a different operating system (OS), not all features are available in each of them, and this is what makes PCL interesting, since we can write reusable code mainly at the business level, without having to we need to worry about the target platform, because we will only have access to the common resources between them.
At this point usually a question arises: What if I want to use a specific feature of the target platform (android for example), but this feature is not available in PCL, how to do?
This type of situation is very recurrent, since each OS has its APIs, and a very common situation is the use of the local storage resources (Storages) of the devices, where each one treats his way.
To solve this kind of problem, we generally run away from the technology itself and use code designation features like IOC , where we pass the specific platforms the responsibility of returning us a resource capable of solving specific problems.
I hope I have helped.