xcode NSString 到 NSUUID 的转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26859508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:09:04  来源:igfitidea点击:

NSString to NSUUID convert

iosobjective-cxcode

提问by shesh nath

how to convert from NSString to NSUUID ? i got the answer for conversion of, NSUUID to NSString but vice versa could not found.like this is my string @"12033030303" alloc NSUUID using this string any help would be appreciated

如何从 NSString 转换为 NSUUID ?我得到了将 NSUUID 转换为 NSString 的答案,但反之亦然找不到。就像这是我的字符串 @"12033030303" 使用此字符串分配 NSUUID 任何帮助将不胜感激

回答by l0gg3r

@"12033030303"is not possible to convert to NSUUID, as Universally Unique Identifier has specification (for example look at wikipedia), this means any random string can't be converted to NSUUID.

@"12033030303"无法转换为 NSUUID,因为 Universally Unique Identifier 有规范(例如查看wikipedia),这意味着任何随机字符串都无法转换为 NSUUID。

initWithUUIDStringshould be the method you're looking for, but it works only if UUID is valid.

initWithUUIDString应该是您正在寻找的方法,但只有在 UUID 有效时才有效。

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"A5D59C2F-FE68-4BE7-B318-95029619C759"];