我已经自学了大约6个月的Objective-C,并且很喜欢使用这种语言。但是我没有找到任何好的编码规范,所以我编写的代码总是看起来不一致。
像命名约定之类的东西完全可以继承下来,但是缩进、间距和(不可能的?)80个字符行宽却表现不佳。
你使用什么样的Objective-C约定呢?
这里是一个小例子,展示了一些问题:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
self.navigationItem.leftBarButtonItem =
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self.parentViewController
action:@selector(done:)] autorelease];
NSString* units = [[NSString alloc] initWithFormat:@"%@", @"oz"];
NSString* optionOne = [[NSString alloc] initWithFormat:@"[%d%@] Calculate", 100, units];
self.options = [[NSMutableArray alloc] initWithObjects:
optionOne,
@"Configure Portions",
@"Configure Notifications",
@"Help",
nil];
[units release];
[optionOne release];
[tableView reloadData];
}
return self;
}