首页 > 其他 > 详细

Objective-C - 容器元素转换NSInteger

时间:2015-07-13 12:21:52      阅读:320      评论:0      收藏:0      [点我收藏+]

容器(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).


技术分享

版权声明:本文为博主原创文章,未经博主允许不得转载。

Objective-C - 容器元素转换NSInteger

原文:http://blog.csdn.net/caroline_wendy/article/details/46858963

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!