码迷,mamicode.com
首页 > 其他好文 > 详细

Objective-C - 容器元素转换NSInteger

时间:2015-07-13 12:24:08      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:mystra   objective-c   容器   nsinteger   

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

标签:mystra   objective-c   容器   nsinteger   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!