Win*_*der 27 coding-style objective-c
我一直在教自己Objective-C大约6个月,并喜欢使用这门语言.但是我没有找到任何好的编码标准,所以我写的代码总是看起来像一个不一致的混乱.
像命名约定这样的东西很好,但是间距,缩进和(不可能的?)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;
}
Run Code Online (Sandbox Code Playgroud)
很好的问题,谢谢你的问题.
我的一些个人编码标准:
[self setOptions:...]在下一行上创建.这使得调试更简单.[object property]表示法.m_或者至少_.但我通常不这样做,因为看起来很难看.善良的人知道我们苹果人讨厌丑陋的事情.:)(对于它的值,在上面的示例中,您可以使用-[NSString stringWithFormat:...]而不是alloc/init/release 直接获取自动释放的字符串.)
| 归档时间: |
|
| 查看次数: |
18010 次 |
| 最近记录: |