【发布时间】:2026-02-09 23:45:01
【问题描述】:
您能否告诉我在非 ARC 世界中哪种方法是正确的以及为什么。
+ (NSString *)getUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString*) string autorelease];
}
或
+ (NSString *)getUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return (NSString*)string;
}
【问题讨论】:
-
我建议改用 NSUUID。
-
@Catfish_Man 我喜欢你的方式,但唯一的问题是 NSUUID 在 iOS 6 中被添加到 Foundation。我的应用目标是 iS 5.0。所以我必须 CFUUIDRef。
标签: ios objective-c memory-management core-foundation