command line tool
@"there are %i in a year.", minutesInyear
代码可以保存
- (int) myFunction (int x, int y) {}
void myFunction(void) {}
string 不是内置的变量类型
NSString *myString = @"hello";
NSDate *today = [NSDate date];
自定义变量类型
typedef int simonsInt;
simonsInt foo = 999;
typedef emun {window = 99} searPreference
#if DEBUG
....
#endif
NSString *msg = @"hello world";
* 指针
NSLog(@"The value of message is %@", message);
[myObject someMethod];
result = [myObject someMethod]
[myobject someMethod:arg];
[myObject insertString: @"Hello" atIndex: 11];
[myObject someMethod: [anotherObject anotherMethod]]
+是类方法 -是instance方法
if you own the object you must release it
if you don`t own the object you must not
alloc new copy retain release
NSDate *myDate = [NSDate new];
NSDate *myDate = [[NSDate alloc] init];
[myDate release];
[fred autorelease] 跟让垃圾回收是两回事,是将fred放到pool里面
[img]http://dl2.iteye.com/upload/attachment/0086/6439/0c20814b-c06f-31b5-92f0-2232184234c1.png[/img]
什么时候使用autorelease:
create {
Employee *fred = [[Employee alloc] init];
[fred autorelease];
return fred;
}
@interface Employee : NSObject
@property NSString *name;
-(void) someMethod;
@end
@implementation Employee
@synthesize name, c;
-(void) someMethod{
NSLog();
}
@end
synthesize创建get set方法
#import "Employee.h"
-(int) addNumber:(int)a toNumber:(int)b;
toNumber 2nd part method name
@interface Player : NSObject
{
//instance variables
int score;
}
@end
NSArray *myarray = [NSArray arrayWithObjects:@"one", @"two", nil];
NSLog(@"the second element is : %@", [myarray objectAtIndex:1]);