usage of Unified API's new types in Xplatform solutions (iOS + Android)

RiccardoMoschetti.1881RiccardoMoschetti.1881 ITMember, University
edited January 2015 in Xamarin University

Hello,
I just followed the "lightning" lecture about the Unified API for iOS. Thanks very much, nicely put.

I'm going to migrate three solutions.

I wonder: what happens to the shared classes of the solutions that have one iOS project and one Android project?

Will 32-bit types "ints" and "floats" be migrated to "nints" and "nfloats" even in the shared classes, which are used also by Android? How will the Android project react to this change?
thanks a lot!
Riccardo

Posts

  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    The new nint and nfloat types are only used for iOS specific types. .NET types which are shared with Android should not be touched or affected. The parser might make a few mistakes converting a shared project which contains platform specific code for iOS in that it changes a definition which is also used in Android. It's probably rare, but I suppose it could happen. In those cases, you will need to manually #ifdef the code into conditional code which is not shared.

    Most of the time, all of your platform-specific code is actually isolated to the iOS project so it should work just fine.

    Good luck!
    mark

  • RiccardoMoschetti.1881RiccardoMoschetti.1881 ITMember, University
    edited January 2015

    Thank you very much Mark.
    There are two cases I'll be going to test:
    1- one solution in which the shared code is actually "shared code"
    2 - one solution in which the shared code is in a class library

    I would be curious to check if nint and nfloat map to any CTS "safe" types. Not that they are gonna be shared in other contexts: just nerd curiosity.

  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    No, they don't map directly to CTS types. They are unique to the Xamarin.iOS runtime and not usable in any other context. They are, in fact, just custom types defined in the Xamarin.iOS assembly - if you pull them up in the Object Browser you can see the source code. Both are structs, nint holds an internal int (32-bit) or long (64-bit) value, and nfloat holds a float (32-bit) or double (64-bit).

Sign In or Register to comment.