iOS 笔记

  1. 使用断言NSAssert()调试程序错误app

NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,经过为NSAssert()传递条件表达式来判定是否属于Bug,知足条件返回真值,程序继续运行,若是返回假值。则抛出异常,而且能够自定义异常描述。NSAssert()是这样定义的:dom

#define NSAssert(condition, desc)spa

condition是条件表达式,值为YES或NO;desc为异常描述,一般为NSString。当condition为YES时程序继续运行,为NO时,则抛出带有desc描述的异常信息。NSAssert()能够出如今程序的任何一个位置。具体事例以下:调试

生成一个LotteryEntry对象时,传入的NSDate不能为nil,加入NSAssert()判断。对象初始化源码以下:code

- (id)initWithEntryDate:(NSDate *)theDate {
    self = [super init];
    if (self) {
        NSAssert(theDate != nil, @"Argument must be non-nil");
        entryDate = theDate;
        firstNumber = (int)random() % 100 + 1;
        secondNumber = (int)random() % 100 + 1;
    }
    return  self;
}

接下来则是生成对象时传入一个值为nil的NSDate,看断言是否运行。对象

LotteryEntry *nilEntry = [[LotteryEntry alloc] initWithEntryDate:nil];blog

 

2. 开发

    设置导航栏和状态栏的背景色:源码

    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:30.0f/255 green:95.0f/255 blue:185.0f/255 alpha:1.0f]];it

    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

相关文章
相关标签/搜索