IOS - Some Notes About Cocoa

First . Sometimes you will encounter such a situation , that your initiazer have to accept some parameters . You have to overwrite base class 'init' method :

- (id)init {
    [self dealloc];
    @throw [NSException exceptionWithName:@"BNRBadInitCall"
    reason:@"Initialize Lawsuit with initWithDefendant:"
    userInfo:nil];
    return nil;
}

 

Second . Somethime you may not find out where the app crash , try the two methods below:

Method A : set a symbolic breakpoint at objc_exception_throw .

Method B : use NSAssert() to throw out the exceptions , for example :

- (id)initWithEntryDate:(NSCalendarDate *)theDate {
    if (![super init]) return nil;
    NSAssert(theDate == nil, @"Argument must be non-nil");
    return self;
}

 

 

posted @ 2013-07-16 15:06  makemelike  阅读(195)  评论(0编辑  收藏  举报