main.m
1 //
2 // main.m
3 // 模型練習(xí)
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轉(zhuǎn)發(fā)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; // 設(shè)置微博的主人
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 專門用來(lái)存數(shù)據(jù)的,稱為模型
42 */
User.h
1 //
2 // User.h
3 // 模型練習(xí)
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 // 姓名、微博號(hào)碼、密碼、頭像、性別、手機(jī)、生日
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 // 模型練習(xí)
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 // 模型練習(xí)
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 // 微博內(nèi)容、微博配圖、發(fā)送時(shí)間、微博發(fā)送人、轉(zhuǎn)發(fā)的微博、被評(píng)論數(shù)、被轉(zhuǎn)發(fā)數(shù)
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 // 如果設(shè)計(jì)成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 // 模型練習(xí)
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