#import <Foundation/Foundation.h>
@interface car:nsobject{
@public
int _wheels;
int _speed;
}
-(void) run;
@end
@implementation Car
-(void) run{
NSLog (@ "%d wheels, with a speed of%d cars running up", _wheels, _speed);
}
@end
void Test1 (Car *newcar) {
Newcar->_wheels = 5;
}
void Test2 (Car *newcar);
int main (int argc, const char * argv[]) {
Car *C1 = [[Car alloc] init];
Car *C2 = [[Car alloc] init];
Test1 (C1);
Test2 (C2);
[C1 run];
[C2 Run];
return 0;
}
void Test2 (Car *newcar) {
Newcar->_wheels = 4;
Newcar->_speed = 300;
}
*/
/*
#import <Foundation/Foundation.h>
@interface persons:nsobject{
@public
NSString *_name;
int _age;
}
-(void) print;
@end
@implementation Persons
-(void) print{
NSLog (@ "name =%@, age =%d", _name, _age);
}
@end
void Sett (Persons *p);
int main (int argc, const char * argv[]) {
Persons *p = [[Persons alloc] init];
Sett (p);
[P print];
return 0;
}
void Sett (Persons *p) {
P->_name = @ "Jerry";
P->_age = 15;
}
*/
#import <Foundation/Foundation.h>
typedef enum{
Sexman,
Sexwoman
} Sex;
typedef enum{
Colorblue,
Colorwhite,
Colorblack,
Colorgreen,
Colorred,
Colororange
} Color;
typedef struct{
int year;
int month;
int day;
} Date;
@interface Person:nsobject
@property NSString *name;
@property int age;
@property sex sex;
@property Color Favcolor;
@property Date birthday;
-(void) print;
@end
@implementation person
-(void) print{
NSLog (@ "name =%@, age =%d, sex =%d, Favcolor =%d, birthday =%d-%d-%d", _name, _age, _sex, _favcolor, _birthday.year, _birthday.month, _birthday.day);
}
@end
int main (int argc, const char * argv[]) {
Person *p = [[Person alloc] init];
P.name = @ "Jerry";
P.age = 10;
P.sex = Sexman;
P.favcolor = Colorwhite;
Date D = {2015, 7, 21};
P.birthday = D;
[P print];
return 0;
}
OC-Simple design of classes with enum and struct