【发布时间】:2013-07-11 21:08:25
【问题描述】:
ios 新手,尝试从函数返回 NSString。据我了解,我需要[NSString... alloc] init] 才能创建要返回的字符串。另外,因为我打电话给alloc,我想我必须自己自动释放对象但是我收到消息“ARC 禁止发送'autorelease'的显式消息”所以..当我完成后如何告诉 ios那分配的NSString?
- (NSString *) generateUID
{
char foo[32];
// create buffer of all capital psuedo-random letters
for (int i = 0; i < sizeof(foo); i++)
foo[i] = (random() % 25) + 65; // 0-25 + CAPITAL_A
NSString *uid = [[NSString alloc] initWithBytes:foo length:sizeof(foo) encoding:NSASCIIStringEncoding];
NSLog (@"uid: %@", uid);
return (uid);
}
【问题讨论】:
-
长话短说:ARC 为您处理。您应该在 Apple Dev 网站上阅读 ARC。