zoukankan      html  css  js  c++  java
  • iOS 笔记

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

    NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值。则抛出异常,并且可以自定义异常描述。NSAssert()是这样定义的:

    #define NSAssert(condition, desc)

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

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

    - (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];

    2. 

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

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

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

  • 相关阅读:
    优秀的JavaScript模块是怎样炼成的(转发)
    从发展历史理解 ES6 Module(转发)
    JavaScript 模块演化简史(转发)
    objcopy 格式转换
    链接操作
    fflush()
    为什么栈地址从高到低生长,堆从低到高
    C语言中,a[-1] (负数下标)的用途
    va_list 、va_start、 va_arg、 va_end 使用说明
    docker 部署 redis
  • 原文地址:https://www.cnblogs.com/wmx-rj/p/4929544.html
Copyright © 2011-2022 走看看