【发布时间】:2013-08-19 04:30:26
【问题描述】:
我正在尝试使用我在这篇文章中找到的代码将 NSArray 转换为 NSDictionary: Convert NSArray to NSDictionary
@implementation NSArray (indexKeyedDictionaryExtension)
- (NSDictionary *)indexKeyedDictionary
{
NSUInteger arrayCount = [self count];
id arrayObjects[arrayCount], objectKeys[arrayCount];
[self getObjects:arrayObjects range:NSMakeRange(0UL, arrayCount)];
for(NSUInteger index = 0UL; index < arrayCount; index++) { objectKeys[index] = [NSNumber numberWithUnsignedInteger:index]; }
return([NSDictionary dictionaryWithObjects:arrayObjects forKeys:objectKeys count:arrayCount]);
}
@end
但是在 [self get objects:array objects,...] 行中存在错误,带有消息:Sending “NSString _strongto parameter of type _unsafe_unretained id* ”change retain/释放指针的属性。我认为这是因为 ARC 问题,因为该帖子是在 2009 年。 有人知道如何解决这个问题吗?谢谢..
【问题讨论】:
-
什么是[自计数]??自己 ??通过 NSLog 在控制台中显示它?和stackoverflow.com/questions/12868603/…
-
创建一个关键字就是索引的字典有什么好处?我看不到。
-
我尝试了 pastebin 链接,但在这一行仍然出错:[self getObjects:arrayObjects range:NSMakeRange(0UL, arrayCount)];
标签: ios objective-c nsdictionary