What is object? Object is a module with a function which can reuse easily in application development.



Define Objective-C class interface.

@interface ClassName: ParentClass {

   ClassMembers;

}

ClassMethods;

@end

--> you can define instance variables in the ClassMembers.

--> you can define called methods in the ClassMethods.



Add instance variables in a class

@interface Account: NSObject{

   double balance;

   long number;

}

@end




Define class methods

-(void) setNumber: (long) y;     // parameter of a long type

-(long) getNumber();               // returned value of a long type

-(void) setAccount: (long)y andBalance: (double)x;     // parameter more than one

--> (-) means instance method, and (+) menans class method.



Define and initialize class instance

Account* account;

account = [Account alloc];

account = [account init];


or


Account* accunt = [[Account alloc] init];



Call a method

[account displayAccountInfo];

[account setAccountNumber: 1234321];

[account setAccountNumber: 12345334 andBalance: 3145.19];


+ Recent posts

출처: http://large.tistory.com/23 [Large]