模型的设计
int main()
{
//新建2个用户
User *u = [[User alloc] init];
u.name = @"2B";
User *u2 = [[User alloc] init];
u2.name = @"傻B";
// 新建2条微博
Status *s = [[Status alloc] init];
s.text = @"今天天气真好!";
s.user = u;
Status *s2 = [[Status alloc] init];
s2.text = @"今天天气真的很好!";
s2.retweetStatus = s;
s2.user = u2;
[u2 release];
[u release];
[s2 release];
[s release];
return 0;
}
typedef enum {
SexMan, // 男
SexWoman // 女
} Sex;
typedef struct {
int year;
int month;
int day;
} Date;
// 姓名、微博号码、密码、头像、性别、手机、生日
@interface User : NSObject
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *account;
@property (nonatomic, retain) NSString *password;
// http://weibo.com/a.png URL
@property (nonatomic, retain) NSString *icon;
@property (nonatomic, assign) Sex sex;
@property (nonatomic, retain) NSString *phone;
@property (nonatomic, assign) Date birthday;
@end
@implementation User
- (void)dealloc
{
[_name release];
[_account release];
[_icon release];
[_password release];
[_phone release];
[super dealloc];
}
@end
#import "User.h"
// 微博内容、微博配图、发送时间、微博发送人、转发的微博、被评论数、被转发数
@interface Status : NSObject
@property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) NSString *icon;
// 从1970-01-01 00:00:00 开始,一共度过了多少毫秒
@property (nonatomic, assign) long time;
//@property (nonatomic) time_t time;
@property (nonatomic, retain) User *user;
@property (nonatomic, retain) Status *retweetStatus;
@property (nonatomic, assign) int commentsCount;
@property (nonatomic, assign) int retweetsCount;
@end
@implementation Status
- (void)dealloc
{
[_text release];
[_user release];
[_retweetStatus release];
[_icon release];
[super dealloc];
}
@end
时间: 2024-10-10 11:11:30