我正在读通过样品代码ListAdder,并且有许多变量之后断言,或几乎所有的方法中使用,例如:为什么在项目中使用'assert'? (为什么使用它这么多次)
self.formatter = [[[NSNumberFormatter alloc] init] autorelease]; assert(self.formatter != nil);
或:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#pragma unused(tv)
#pragma unused(indexPath)
UITableViewCell * cell;
assert(tv == self.tableView);
assert(indexPath != NULL);
assert(indexPath.section < kListAdderSectionIndexCount);
assert(indexPath.row < ((indexPath.section == kListAdderSectionIndexNumbers) ? [self.numbers count] : 1));
我想知道,有什么意思呢?
感谢
我不了解Objective C,但用其他语言可以在编译时禁用它们,这样它们不会减慢实时系统的速度,但可以在测试和分级过程中将它们用于错误检测。 – corsiKa