您的位置:首页 > 移动开发 > IOS开发

iOS开发问题集锦

2016-04-13 12:40 399 查看



NSStringFromSelector(_cmd)

_cmd是隐藏的参数,代表当前方法的selector,他和self一样都是每个方法调用时都会传入的参数,动态运行时会提及如何传的这两个参数,

该方法一般用于log中,执行这个方法就会输出方法的名称,这样做是为了跟踪查看方法调用的前后顺序,或者想看看程序到底在那个方法内部崩溃的

int,NSInteger,NSUInteger,NSNumber之间的区别和联系

int是32位的整数,而NSInteger与设备无关,不用考虑设备是32位还是64位,推荐用NSInteger

NSUInteger是无符号的,即没有负数

NSInteger是基础类型,而NSNumber是一个类,类似于java中int与integer的关系

NSNumber * intNumber = [[NSNumber alloc] initWithInt:5];
NSNumber * floatNumber = [[NSNumber alloc] initWithFloat:3.14f];
NSNumber * doubleNumber = [[NSNumber alloc] initWithDouble:6.7];
NSNumber * charNumber = [[NSNumber alloc] initWithChar:'A'];

(http://www.cnblogs.com/GISerYang/p/3340764.html)

NSNumber应该用strong修饰,因为是不可变的(immutable),见 http://www.jianshu.com/p/26210296fa02
IOS网络开发NSURLSession http://blog.csdn.net/hello_hwc/article/details/44565115
sizeWithFont is deprecated的解决方法

sizeWithFont从iOS7开始已经废弃,官方推荐用sizeWithAttributes方法,具体的使用方式为

NSDictionary *attributes = @{NSFontAttributeName: self.titleLabel.font};CGSize badgeSize = [badgeValue sizeWithAttributes:attributes];


NSString转换为int

NSString *str = @"200";int code = [str intValue];


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: