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() % + ;
secondNumber = (int)random() % + ;
}
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]];

iOS 笔记的更多相关文章

  1. 荼菜的iOS笔记--UIView的几个Block动画

    前言:我的第一篇文章荼菜的iOS笔记–Core Animation 核心动画算是比较详细讲了核心动画的用法,但是如你上篇看到的,有时我们只是想实现一些很小的动画,这时再用coreAnimation就会 ...

  2. IOS笔记 1

    < ![CDATA[ 笔记 UIWindows 与UIView的关系iOS的坐标系统视图层次结构视图坐标(Frame和Bounds区别)UIView的常用属性和方法坐标系统的变换UIView内容 ...

  3. 【转】iOS笔记-自定义控件(OC)

    原文网址:http://www.jianshu.com/p/f23862eb7b8a 导读: iOS开发中,很多时候系统提供的控件并不能很好的满足我们的需求,因此,自定义控件便成为搭建UI界面中必不可 ...

  4. iOS笔记———数据存储

    应用沙盒:应用文件系统的根目录,每个应用都有独自的沙盒相互:在xcode中可以用NSHomeDirectory()函数,打印当前应用的沙盒根路径. 应用程序包:包含了所有资源文件和执行文件; * Do ...

  5. Xamarin开发IOS笔记:切换输入法时输入框被遮住

    在进行IOS开发的过程中,出现类似微信朋友圈的交互界面,当用户遇到感兴趣的内容可以进行评论.为了方便评论输入,当出现评论输入框的时候自动将评论输入框移动至键盘的上方,这样方便边输入边查看. 当用户隐藏 ...

  6. 【IOS笔记】Delegation

    Delegation Delegation is a simple and powerful pattern in which one object in a program acts on beha ...

  7. 【IOS笔记】Event Delivery: The Responder Chain

    Event Delivery: The Responder Chain  事件分发--响应链 When you design your app, it’s likely that you want t ...

  8. 【IOS笔记】Gesture Recognizers

    Gesture Recognizers Gesture recognizers convert low-level event handling code into higher-level acti ...

  9. 【IOS笔记】About Events in iOS

    About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...

  10. 【IOS笔记】Resource Management in View Controllers

    Resource Management in View Controllers 视图控制器的资源管理 View controllers are an essential part of managin ...

随机推荐

  1. python初学day01

    1.执行Python脚本时打印的字符有颜色 1. print "\033[32;1mhello\033[0m" #打印绿色 2. print "\033[31;1mhel ...

  2. leveldb 学习笔记之VarInt

    在leveldb在查找比较时的key里面保存key长度用的是VarInt,何为VarInt呢,就是变长的整数,每7bit代表一个数,第8bit代表是否还有下一个字节, 1. 比如小于128(一个字节以 ...

  3. 第四十三章 微服务CICD(5)- gitlab + jenkins + docker + dockerregsitry

    一.总体流程 部署: 开发机(mac) ip:11.11.11.11 docker:1.12.1 部署机(centos7) ip:10.211.55.4 docker:1.12.3 生产机(cento ...

  4. 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()

    在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException:  Can't create handler inside thread that has ...

  5. NPOI简单应用

    打开或创建文件 fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); 不同版本的workbook if ...

  6. 获取IMap上绘制的Element的区域范围

    运行环境:开发环境:Windows7旗舰版64bit.VisualStudio2008 With SP1.ArcEngine10.0.NetFrameWork4.0.IIS7和C#开发语言. 问题描述 ...

  7. 部署war包后,新增tomcat服务器,启动tomcat服务器报错解决方法

    导入Maven工程后,新增tomcat服务器,启动服务器后,报如下错误: 使用http访问页面的时候报如下错误: 经过百度后,有一种方法可以解决: 在eclipse tomcat无法启动,无法访问to ...

  8. (原创)通用查询实现方案(可用于DDD)[附源码] -- 设计思路

    [声明] 写作不易,转载请注明出处(http://www.cnblogs.com/wiseant/p/3988592.html).   [系列文章] 通用查询实现方案(可用于DDD)[附源码] -- ...

  9. C#实现MS-Office文档转Pdf(Word、Execel、PowerPoint、Visio、Project)

    using System; using Microsoft.Office.Core; namespace Office { class Util { private Util() { } /// &l ...

  10. [linux] 默认权限修改(umask)

    1 文件默认权限 对于目录,默认权限=777-umask 对于文件,默认权限=666-umask(文件默认无执行权限) 默认权限修改: vim /etc/bashrc 71行是普通用户的更改,73是超 ...