目标C:读取id类型为<- (NSInteger)countForItem:(id<NSObject>)item { return [item[CountKey] integerValue]; }

问题描述 投票:0回答:1
这将引发错误“读取id<NSObject>类型的对象上找不到词典元素的预期方法
CountKey声明为:static NSString *CountKey = @"count";

任何帮助将不胜感激。谢谢!

-(NSInteger)countForItem:(id

)item {return [item [CountKey] integerValue]; }这将引发错误“用于读取在id&...类型的对象上找不到的字典元素的预期方法”

objective-c xcode nsobject
1个回答
0
投票
return [(NSDictionary*)(item)[CountKey] integerValue];
© www.soinside.com 2019 - 2024. All rights reserved.