#import <Foundation/Foundation.h>
@interface Car : NSObject{
@public
int _wheels;
int _speed;
}
- (void)run;
@end
@implementation Car
- (void)run{
NSLog(@"%d个轮子, 速度为%d的车子跑起来了", _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;
}