NSUUID到NSString

Bir*_*ibu 20 uuid objective-c ios

我需要以NSString格式从手机获取deviceUUID.现在我有这个:

NSString *deviceId = [UIDevice currentDevice].identifierForVendor;
Run Code Online (Sandbox Code Playgroud)

因为我以前拥有的是:

NSString *deviceId = [UIDevice currentDevice].uniqueIdentifier;
Run Code Online (Sandbox Code Playgroud)

现在给我一个错误.

但是在第一句话中,我收到了警报:

Incompatible pointer types initializing 'NSString *' with an expression of type 'NSUUID *'
Run Code Online (Sandbox Code Playgroud)

Mat*_*uch 61

正如错误告诉您的那样,identifierForVendor返回类的对象NSUUID,而不是NSString.

如果你需要一个NSString使用这个:

NSUUID *identifierForVendor = [[UIDevice currentDevice] identifierForVendor];
NSString *deviceId = [identifierForVendor UUIDString];
Run Code Online (Sandbox Code Playgroud)


onm*_*133 24

对于任何想要如何将NSUUID转换为NSString的人

ObjC

NSString *uuid = [[NSUUID UUID] UUIDString];
Run Code Online (Sandbox Code Playgroud)

迅速

NSUUID().UUIDString
Run Code Online (Sandbox Code Playgroud)

斯威夫特3

UUID().uuidString
Run Code Online (Sandbox Code Playgroud)