容器(NSMutableArray, NSMutableDictionary)的获取元素方法objectForKey:返回id类型,
转换NSInteger类型, 使用integerValue.
// newQuestion is an NSDictionary defined somewhere
NSInteger questionId = [[newQuestion objectForKey:@"question_id"] integerValue];
Just to be clear, the compiler won’t complain about sending any message to an id, instead if the object isn’t really an object (a struct or primitive), or doesn’t respond to that message, you’ll get an exception at runtime (not at build).
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-14 13:54:58