Xamarin.Forms - Shared Project x PCL

Asked

Viewed 128 times

0

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 advantages and disadvantages?

1 answer

0

Shared projects have a very similar concept 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, for execution of specific resources of each platform:

#if Android
    // Escreva um código utilizando um recurso do android
#endif

Already PCL (Portable Class Library) projects, as its name already says, are projects that allow the creation of code compatible between the 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 assemblies, and compatible between them.

Because they are different Operating Systems (OS), then not all resources are available in each of them, and this is what makes the PCL interesting, since we can write reusable code mainly at the business level, without having to worry about the target platform necessarily, because we will only have access to the common resources between them.

At this point usually arises a question: What if I want to use a specific feature of the target platform (android for example), but this feature is not available on 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 local storage resources (Storages) of the devices, where each treats its own way.

To solve this type of problem, we usually run away from the technology itself and use code designator features such as IOC, where we pass the specific platforms the responsibility to return us a resource capable of solving specific problems.

I hope I’ve helped.

  • If I use Sqlite, which type would be more suitable?

  • @Roberta, I didn’t understand what you meant by more indicated type, could exemplify where/how you want to use it?

  • I want to create an APP for IOS and Android, in Xamarin.Forms. A News App for example, where I will store them inside Sqlite (after searching via JSON). In this scenario, which is more indicated, PCL or shared?

  • @Roberta, in this scenario I would use PCL, but it would be a particular choice of mine due to what I mentioned above, I can’t say to you, use this or that, because it even goes against the good practices of forum responses.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.