Search code examples
ios.netuuid

Is NSUUID *really* the same as .Net GUID? And Android?


I'm familiar with the iOS NSUUID().uuidString for generating UUIDs, but I am less clear on the corresponding .Net functionality.

According to this post there is a subtlety involved, but it is not clear to me whether this applies to UUID's when used with .toString().

Has anyone out there passed UUIDs between these platforms that might have some more detailed comments? "It just works" is fine too!

There is a fleeting chance I might want to use these on Android as well, so any comments about moving them between all three are even more useful.


Solution

  • The uuidString is indeed the same format as a guid is. The toString of an NSUUID however is different, it contains more data. So passing this to .NET and parsing it as guid would raise an exception. (not sure for android)

    If you are using swift you can just use UUID().uuidString of which I'm certain it works.

    As far as answering your complete question. A UUID generated in iOS uses a different algorithm than in .NET so there will be subtle differences, but they are unique nevertheless so that's not something to worry about.