objective-c语法

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]);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值