Mooney Wang

这是本站的副标题


  • 首页

  • 归档

NSAssert浅析

发表于 2016-04-20

NSAssert浅析

作用

当给定的条件为false时,直接生成一个断言。

声明

1
#define NSAssert(condition, desc, ...)
参数 描述
condition 表达式,值为YES或者NO
desc NSString对象,一般会写一段描述错误信息的字符串,可以包含参数的占位符
… 用于填充desc字符串中的占位符的参数

用法

当程序处于Debug状态下,如果condition值为NO,那么程序会抛出一个异常,控制台会打印出desc。当程序处于Release状态下,断言不会执行。
所以我们一般可以利用断言来调试程序,举个例子:

1
NSAssert(self.dataSource != nil, @"必须设置dataSource");

我们在程序中添加了一条断言,如上,这句话的意思是必须要设置数据源,一旦self.dataSource没有设置,那么程序Debug时就会抛出异常,并且打印“必须设置dataSource”这句话,这样我们就能避免忘记设置数据源。

Hello World

发表于 2016-04-19

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

Mooney Wang

Mooney Wang

这里是站点描述

2 日志
© 2016 Mooney Wang
由 Hexo 强力驱动
主题 - NexT.Mist