【非凡程序员】简单的转发功能

      首先实现转发功能之前分析这个模块需要的对象的对象是发的人和转发的人以及转发的文章,所以创建两个类分别是Person类和weibo类,而人的对象所有的属性是姓名、年龄、生日、签名、以及微博;微博的属性有标题、内容、创作时间,发的人以及转发人;分析完之后代码实现,先创建两个类:

      1、person类中person.h文件代码是:

 #import <Foundation/Foundation.h>
@class weibo;
@interface person:NSObject
@property(nonatmic,weak)NSString *name;
@property(nonatmic,assign)int age;
@property(nonatmic,weak)NSString *birthday;
@property(nonatmic,weak)NSString *sign;
@property(nonatmic,weak)weibo *weibo;
@end

2、person类中person.m文件代码是:

 #import "person.h"
@implementation
-(void)dealloc
{
   NSLog("%@对象释放……",_name);
}
@end

3、weibo类中weibo.h文件代码是

  #import <Foundation/Foundation.h>
@class person;
@interface weibo:NSObject
@property(nonatmic,weak)NSString *title;
@property(nonatmic,weak)NSString *content;
@property(nonatmic,weak)NSString *date;
@property(nonatmic,weak)person *sendperson;
@property(nonatmic,weak)person *resendperson;
@end

4、weibo类中weibo.m文件代码是

  #import "weibo.h"
@implementation
-(void)dealloc
{
   NSLog("%@对象释放……",_title);
}
@end

5、在main.m的文件中实现部分

 //先实例化一个发微博的人Author
person *Author=[[person alloc]init];
[Author setName:@"Alice"];
[Author setAge:20];
[Author setBirthday:@"02-09"];
[Author setSign:@"~~~~~~~"];
//再从微博类实例化一篇微博
weibo *News=[[weibo alloc]init];
[News setTitle:@"奇酷手机"];
[News setContent@"奇虎360"];
[News setDate@"2015-05-21"];
//Author发了一篇微博
[Author setWeibo:News];
NSLog(@"一篇 title],[Author name],[News date]);
//现在有一个人转发这篇文章,所以我再实例化一个转发微博的人
person *resend=[[person alloc]init];
[resend setName:@"Hilary"];
[weibo setResendperson:resend];
NSLog(@,[weibo title],[resend name],[News date]);

你可能感兴趣的:(【非凡程序员】简单的转发功能)