//
Main.m
- the relationship between objects and methods
//
Created by Vic fan on 16/7/14.
copyright©2016 year Li Hongqiang . All rights reserved.
//
/**
*
OC has a method of having a parameter return value
declaration with parameter return value method
-(int) sum: (int) x AndY: (int) y;
-(int) sum: (int) x AndY: (int) y{
return x+y;
relationship :
1 object as the parameter of the method ;
ways to display people's information
-(void) Showperson: (person *) person;
2 object as the return value of the method
denaturing Methods
-(Person *) Changesex: [person *] person;
*
*/
#import <Foundation/Foundation.h>
/**
* Declaration of Class
*/
/**
Define Gender enumeration
*/
typedef enum{
//0 1 2
Ksexwomen,ksexman,ksexyao
}sex;
@interface person : nsobject{
@public
nsstring *_name; name
int _age; Age
Sex _sex; sex
}
/**
* declaration of Methods
*/
-(void) Showperson: (person *) person;
-(person *) Changesex: [person *] person;
@end
@implementation Person
-(void) Showperson: (person *) person{
NSLog(@ " name :%@, age :%d, gender :%d",person->_name,person-> _age,person->_sex);
}
-(person *) Changesex: (person *) person{
person->_sex = ksexwomen;
return person ;
}
@end
int Main (int argc, const Char * argv[]) {
@autoreleasepool {
/**
* Create Objects
*/
person *p = [person new];
/**
* assigning value to an instance variable of an object
*/
p->_age = ;
p->_name = @ " Jay Chou ";
p->_sex = Ksexman;
/**
* Call Method
*/
[P Showperson:p];
NSLog(@ " sex :%d",p->_sex);
person *p2 = [P changesex:p];
NSLog(@ " sex :%d",p2->_sex);
}
return 0;
}
Li Hongqiang iOS Development oc[018] The relationship between objects and methods