码迷,mamicode.com
首页 > 其他好文 > 详细

Objective-C - 模型的设计

时间:2015-04-21 09:39:21      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:objective   模型的设计   

模型的设计

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

Objective-C - 模型的设计

标签:objective   模型的设计   

原文地址:http://blog.csdn.net/wangzi11322/article/details/45165899

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!