IOS開發之微博的設計與實現
//// main.m// Microblog//#import #import Person.h#import BlogMaster.h#import Microblog.hint main(int argc, const char * argv[]){ Person * person = [[Person alloc]init]; [person showName]; NSLog(@%@,person); Person * man = [[Person alloc]init]; [man showName]; //Microblog * microblog = [[Microblog alloc]init]; return 0;}
#import @interface Person : NSObject{ /**用來記錄人的名字*/ NSString * _name; /**用來記錄人的年齡*/ int _age; /**用來記錄出生年月*/ NSString * _birthday; /**用來記錄性別*/ char _sex; /**用來記錄所在地*/ NSString * _address; /**用來記錄感情狀況*/ NSString * _emotion; /**用來記錄血型*/ NSString * _bloodType;}@property NSString * name;@property int age;@property NSString * birthday;@property char sex;@property NSString * address;@property NSString * emtion;@property NSString * bloodType;-(void)showName;@end
#import Person.h#import @implementation Person-(void)showName{ NSLog(@列印人的名字); //NSLog(@%@,_name);}-(NSString *)description{ return [NSString stringWithFormat:@名字=%@ 年齡=%d 出生日期=%@性別=%c 住址=%@ 感情狀況=%@ 血型=%@,_name,_age,_birthday,_sex,_address,_emotion,_bloodType]; }@end
#import #import BlogMaster.h#import Person.h@interface Microblog : NSObject{ /**用來儲存博主資訊*/ //BlogMaster * _blogMaster; /**用來儲存註冊時間*/ NSString * _registerTime; /**簡介*/ NSString * _introductionAboutBlog; /**用來記錄部落格內容*/ NSString * _blogContent; /**用來記錄評論內容*/ NSString * _commentContent; /**用來記錄評論數量*/ int _commentAmount; /**用來記錄點贊數量*/ int _praiseAmount; /**用來記錄微博發表時間*/ NSString * _publishTime; /**用來記錄轉寄數量*/ int _transpond;}@property NSString * registerTime;@property NSString * introductionAboutBlog;@property NSString * blogContent;@property NSString * commentContent;@property NSString * publishTime;@property int commentAmount;@property int praiseAmount;@property int transpond;//-(void)printBlogMasterName:(Person *)person;@end
#import Microblog.h@implementation Microblog//-(void)printBlogMasterName:(Person *)person//{// if([Person isKindOfClass:[BlogMaster class]])// {// BlogMaster * master = (BlogMaster *)person;// }// [master showName];//}-(NSString *)description{ return [NSString stringWithFormat:@ 部落格內容=%@ 評論數量=%d 點贊數量=%d 發表時間=%@ 轉寄數量=%d,_blogContent,_commentAmount,_praiseAmount,_publishTime,_transpond];}@end
#import Person.h@interface BlogMaster : Person{ }-(void)showName;@end
#import BlogMaster.h@implementation BlogMaster-(void)showName{ NSLog(@博主的名字);}@end