void *ptr = &value + 10 * 3;
NewType a = (NewType)b;
for (int
i = 0; i < 10;
i++)
{
doCoolThings();
}
数组和字典类型的字面值的方括号两边各放置一个空格。
NSArray *theShit = @[
@1, @2, @3
];
hasSomeArgs);
NSArray *theShit = @[
@"Got some long string objects in here.",
[AndSomeModelObjects too],
@"Moar strings."
];
NSDictionary *keyedShit = @{
@"this.key": @"corresponds to this value",
@"otherKey": @"remoteData.payload",
@"some": @"more",
@"JSON": @"keys",
@"and": @"stuff",
};
if (user.isHappy) {
//Do something
}
else {
//Do something else
}
if (!error) {
return success;
}
if (!error)
return success;
NSError *error;
if (![self trySomethingWithError:&error]) {
// Handle Error
}
NSError *error;
[self trySomethingWithError:&error];
if (error) {
// Handle Error
}
@interface CustomModelViewController : TTViewController <
TTModelDelegate,
TTURLRequestDelegate
> {
[object/class thing+condition];
[object/class thing+input:input];
[object/class thing+identifer:input];
realPath = [path stringByExpandingTildeInPath];
fullString = [string stringByAppendingString:@"Extra
Text"];
object = [array objectAtIndex:3];
// 类方法
newString = [NSString stringWithFormat:@"%f",1.5];
newArray = [NSArray arrayWithObject:newString];
recipients = [email recipientsSortedByLastName];
newEmail = [CDCEmail emailWithSubjectLine:@"Extra
Text"];
emails = [mailbox messagesReceivedAfterDate:yesterdayDate];
[object adjective+thing];
[object adjective+thing+condition];
[object adjective+thing+input:input];
capitalized = [name capitalizedString];
rate = [number floatValue];
newString = [string decomposedStringWithCanonicalMapping];
subarray = [array subarrayWithRange:segment];
-sortInfo // 是返回排序结果还是给info做排序
-refreshTimer // 返回一个用于刷新的定时器还是刷新定时器
-update // 更新什么,如何更新
-currentSortInfo // "current" 清楚地修饰了名词SortInfo
-refreshDefaultTimer // refresh是一个动词。
-updateMenuItemTitle // 一个正在发生的动作
color = [NSColor colorWithCalibratedHue: 0.10
saturation: 0.82
brightness: 0.89
alpha: 1.00];
//MyViewController.h文件
@interface MyViewController : UIViewController<
UITalbeViewDataSource,
UITableViewDelegate> {
@private:
UITableView *_myTableView; // 私有实例变量
}
// 内部使用的属性
@property (nonatomic,strong) NSNumber *variableUsedInternally;
- (void)sortName; // 只用于内部使用的方法
@end
//MyViewController.m文件使用类扩展
@interface MyViewController()<
UITalbeViewDataSource,
UITableViewDelegate> {
UITableView *_myTableView;
// 外部需要访问的实例变量声明为属性,不需要外部访问的声明为实例变量
NSNumber * variableUsedInternally;
}
// 从Xcode4.3开始,可以不写方法的前置声明,Interface
Builder和Storyboard仍然可以找到方法的定义
@end
- (void) setTitle: (NSString *) aTitle;
- (void) setName: (NSString *) newName;
- (id) keyForOption: (CDCOption *) anOption
- (NSArray *) emailsForMailbox: (CDCMailbox *) theMailbox;
- (CDCEmail *) emailForRecipients: (NSArray *) theRecipients;
for (i = 0; i < count; i++) {
oneObject =
[allObjects objectAtIndex:
i];
NSLog (@"oneObject: %@", oneObject);
}
NSEnumerator *e = [allObjects objectEnumerator];
id item;
while (item =
[e nextObject])
NSLog (@"item: %@", item);
@interface RNCSection: NSObject
@property (nonatomic) NSString *headline;
@end
@interface RNCSection : NSObject {
NSString *headline;
}
@interface RNCSection : NSObject {
NSString *headline;
}
@property (nonatomic) NSString *headline;
@end
@interface RNCSection: NSObject
@property (nonatomic) NSString *headline;
@end