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

  • 相关阅读:
    活动安排问题
    喵哈哈村的魔法考试 Round #5 (Div.2) C
    梯度下降,牛顿法 ,高斯牛顿法
    SSD模型解析
    训练较深的卷积神经网络时遇到的问题
    手写体识别
    Fast Patch-based Style Transfer of Arbitrary Style 理解
    多任务学习
    迁移学习(训练数据少的可怜时的办法)
    通过训练得出的结果修改模型
  • 原文地址:https://www.cnblogs.com/wmx-rj/p/4929544.html
Copyright © 2020-2023  润新知