系统调试

断言

//Debug模式下判断condition条件为假,终止程序,并抛出异常,并显示原因
//release模式下不会终止程序,不会抛出异常
//和普通代码写在一起
NSAssert(condition, desc) 
NSCAssert(condition, desc)

//建议使用NSCAssert,这个宏当中没有使用self,可以避免循环引用
NSAssert([str isEqualToString:@"coc"], @"这是啥呀");
NSCAssert([str isEqualToString:@"cos"], @"这又是啥呀");

//条件为假,则抛出异常,crash指出相应位置
NSParameterAssert(condition)
NSParameterAssert([str isEqualToString:@"cob"]);

单元测试

  • 单元测试断言
//专门用于单元测试
XCTAssert(expression, ...)expression为true时通过,否则测试失败。XCTAssertTrue(expression, ...)expression为true时通过否则测试失败。
XCTAssertFalse(expression, ...)expression为false时通过否则测试失败。

//expression接受id类型
XCTAssertEqualObjects(expression1, expression2, ...)
expression1和expression1对象地址相同时通过,否则测试失败。

XCTAssertNotEqualObjects(expression1, expression2, ...)
expression1和expression1地址不相同时通过,否则测试失败。
  • 测试方法
-(void)setUp {
    [super setUp];
    //测试方法前调用
    // Put setup code here. This method is called before the invocation of each test method in the class.
}
-(void)tearDown {
     //测试方法后调用
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}
-(void)testExample {
     //所有的测试方法都以test开始,且没有参数。
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
   
}

宏定义

//##表示直接在后面拼接
#define WeakSelf(type) __weak typeof(type) weak##self = type
//#表示后面的标识符加双引号
#define WF(str) [NSString stringWithFormat:@"%@",@#str]

你可能感兴趣的:(系统调试)