main.m
1 //
2 // main.m
3 // 模型练习
4 //
5 // Created by sixleaves on 15/5/9.
6 // Copyright (c) 2015年 itcast. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10 #import "User.h"
11 #import "Status.h"
12
13
14 int main(int argc, const char * argv[]) {
15
16 Status *s = [[Status alloc] init];
17 s.text = @"今天天气真好!";
18
19 Status *s2 = [[Status alloc] init];
20 s2.text = @"嘻嘻";
21 s2.retweet = s; // s2转发s这条微博
22
23 User *u = [[User alloc] init];
24 u.name = @"gh";
25 User *u2 = [[User alloc] init];
26 u2.name = @"swp";
27
28 s.user = u; // 设置微博的主人
29 s2.user = u2;
30
31 [u2 release];
32 [u release];
33 [s2 release];
34 [s release];
35 return 0;
36 }
37
38
39 /*
40 什么是模型:
41 专门用来存数据的,称为模型
42 */
User.h
1 //
2 // User.h
3 // 模型练习
4 //
5 // Created by sixleaves on 15/5/9.
6 // Copyright (c) 2015年 itcast. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10
11 // 姓名、微博号码、密码、头像、性别、手机、生日
12 // 用户模型
13 typedef enum {
14
15 SexMan, // 男
16 SexWoman // 女
17
18 }Sex;
19
20 typedef struct {
21
22 int year;
23 int month;
24 int day;
25
26 }Date;
27
28 @interface User : NSObject
29
30 @property (nonatomic, retain) NSString * name;
31
32 @property (nonatomic, retain) NSString * account;
33
34 @property (nonatomic, retain) NSString * password;
35
36 @property (nonatomic, retain) NSString * icon;
37
38 @property (nonatomic, assign) Sex sex;
39
40 @property (nonatomic, retain) NSString * phone;
41
42 @property (nonatomic, assign) Date birthday;
43
44 @end
45
User.m
1 //
2 // User.m
3 // 模型练习
4 //
5 // Created by sixleaves on 15/5/9.
6 // Copyright (c) 2015年 itcast. All rights reserved.
7 //
8
9 #import "User.h"
10
11 @implementation User
12
13 - (void)dealloc
14 {
15 [_name release];
16 [_account release];
17 [_icon release];
18 [_password release];
19 [_phone release];
20
21 [super dealloc];
22 }
23
24 @end
25
Status.h
1 //
2 // Status.h
3 // 模型练习
4 //
5 // Created by sixleaves on 15/5/9.
6 // Copyright (c) 2015年 itcast. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10
11 // 微博内容、微博配图、发送时间、微博发送人、转发的微博、被评论数、被转发数
12
13 @class User;
14
15 @interface Status : NSObject
16
17 @property (nonatomic, retain) NSString *text;
18
19 @property (nonatomic, retain) NSString *icon;
20
21 @property (nonatomic, assign) time_t time;
22
23 // 如果设计成NSString*不好的原因,
24 @property (nonatomic, retain) User *user;
25
26 @property (nonatomic, retain) Status * retweet;
27
28 @property (nonatomic, assign) int commentsCount;
29
30 @property (nonatomic, assign) int retweetsCount;
31
32 @end
33
Status.m
1 // 2 // Status.m
3 // 模型练习
4 //
5 // Created by sixleaves on 15/5/9.
6 // Copyright (c) 2015年 itcast. All rights reserved.
7 //
8
9 #import "Status.h"
10 #import "User.h"
11 @implementation Status
12 - (void)dealloc
13 {
14 [_text release];
15 [_user release];
16 [_retweet release];
17 [_icon release];
18
19 [super dealloc];
20 }
21
22
23 @end
24