ITeye博客

objective-c语法

mistbow · 2013-07-06 19:47 · objective-c · 移动开发 · Markdown

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里面

什么时候使用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)

暂无评论。

评论功能维护中,当前仅展示历史评论。