//
// News.h
// NewsReader
//
//
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface News : NSObject <NSCoding,NSCopying>
{
NSString* subject;
//NSURL* link;
NSString* description;
}
@property(nonatomic,copy)NSString* subject;
//@property(nonatomic,copy)NSURL* link;
@property(nonatomic,copy)NSString* description;
-(id)initwithsubject:(NSString*)_subject
anddescription:(NSString*)_description;
-(void)dealloc;
- (id)copyWithZone:(NSZone *)zone;
-(void)encodeWithCoder:(NSCoder *)aCoder;
-(id)initWithCoder:(NSCoder *)aDecoder;
-(NSString*)description;
@end
//
// News.m
// NewsReader
//
//
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "News.h"
@implementation News
@synthesize subject;
@synthesize description;
-(id)initwithsubject:(NSString*)_subject
anddescription:(NSString*)_description{
if(!_subject||!_description){
[self release];
return nil;
}
self=[super init];
if(!self){
return nil;
}
subject=[NSString stringWithString:_subject];
description=[NSString stringWithString:_description];
return self;
}
-(void)dealloc{
[super dealloc];
}
- (id)copyWithZone:(NSZone *)zone{
News* n=[[News allocWithZone:zone]initwithsubject:@"科技" anddescription:@"日新月异"];
return n;
}
-(void)encodeWithCoder:(NSCoder *)aCoder{
[aCoder encodeObject:subject forKey:@"subject"];
[aCoder encodeObject:description forKey:@"description"];
}
-(id)initWithCoder:(NSCoder *)aDecoder{
if (self=[super init]) {
self.subject= [aDecoder decodeObjectForKey:@"subject"];
self.description=[aDecoder decodeObjectForKey:@"description"];
}
return self;
}
-(NSString*)description{
NSString* d=[[NSString alloc]initWithFormat:@"subject is %@,description is %@",subject,description];
return d;
}
@end
//
// Channel.h
// NewsReader
//
// Created by zz
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "News.h"
@class News;
@interface Channel : NSObject
{
NSMutableArray *newslist;
NSString * description;
}
@property(nonatomic,copy)NSMutableArray* newslist;
@property(nonatomic,copy)NSString* description;
-(id)initwithdescription:(NSString*)_description;
-(void)Addnews:(News*)_new;
-(void)Removenews:(NSInteger)index;
-(News*)newsatindex:(NSInteger)index;
-(void)dealloc;
-(NSString* )description;
@end
//
// Channel.m
// NewsReader
//
// Created by zz
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "Channel.h"
#import "News.h"
@implementation Channel
@synthesize description;
@synthesize newslist;
-(id)initwithdescription:(NSString*)_description{
if(!_description){
[self release];
return nil;
}
self=[super init];
if(!self){
return nil;
}
description=[NSString stringWithString:_description];
newslist=[[NSMutableArray alloc]init];
return self;
}
-(void)Addnews:(News*)_new{
[newslist addObject:_new];
}
-(void)Removenews:(NSInteger)index{
[newslist removeObjectAtIndex:index];
}
-(News*)newsatindex:(NSInteger)index{
return [newslist objectAtIndex:index];
}
-(void)dealloc{
[newslist release];
[super dealloc];
}
-(NSString* )description{
NSMutableString* ns=[[NSMutableString alloc]init];
for(id item in newslist){
[ns appendFormat:@"%@\n",[item description]];
}
return ns;
}
@end
//
// Channelmanager.h
// NewsReader
//
//
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@class Channel;
@interface Channelmanager : NSObject <NSCoding>
{
NSMutableDictionary* Channellist;
NSString* filename;
}
@property(nonatomic,copy)NSMutableDictionary* Channellist;
@property(nonatomic,copy)NSString* filename;
-(id)initwithfilename:(NSString*)_filename;
-(void)Addchannel:(Channel*)_channel forKey:(NSString*)_key;
-(void)RemovechannelForKey:(NSString*)_key;
-(Channel*)channelForKey:(NSString*)_key;
-(void)save;
-(void)read;
-(void)dealloc;
-(NSString*)description;
-(void)encodeWithCoder:(NSCoder *)aCoder;
-(id)initWithCoder:(NSCoder *)aDecoder;
@end
//
// Channelmanager.m
// NewsReader
//
//
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "Channelmanager.h"
#import "Channel.h"
@implementation Channelmanager
@synthesize Channellist;
@synthesize filename;
-(id)initwithfilename:(NSString*)_filename{
if(!_filename){
[self release];
return nil;
}
self=[super init];
if(!self){
return nil;
}
filename=[NSString stringWithString:_filename];
Channellist=[NSMutableDictionary dictionary];
return self;
}
-(void)Addchannel:(Channel*)_channel forKey:(NSString*)_key{
[Channellist setObject:_channel forKey:_key];
}
-(void)RemovechannelForKey:(NSString*)_key{
[Channellist removeObjectForKey:_key];
}
-(Channel*)channelForKey:(NSString*)_key{
return [Channellist valueForKey:_key];
}
-(void)save{
//[Channellist writeToFile:filename atomically:YES];
// NSLog(@"chalist =====%@",Channellist);
[NSKeyedArchiver archiveRootObject:[self description] toFile:filename];
}
-(void)read{
Channellist= [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
[Channellist writeToFile:@"/tmp/qq.txt" atomically:YES];
NSLog(@"%@",Channellist);
}
-(void)dealloc{
[filename release];
[super dealloc];
}
-(NSString*)description{
NSMutableString* ns=[[NSMutableString alloc]init];
for(id item in Channellist){
[ns appendFormat:@"%@",[Channellist valueForKey:item]];
// NSLog(@"909090_____---%@",item);
}
//NSLog(@"---------------------55======value is %@",[Channellist valueForKey:@"cc1"]);
[ns autorelease];
return ns;
}
-(void)encodeWithCoder:(NSCoder *)aCoder{
[aCoder encodeObject:Channellist forKey:@"Channellist"];
[aCoder encodeObject:filename forKey:@"filename"];
}
-(id)initWithCoder:(NSCoder *)aDecoder{
if((self=[super init])){
self.Channellist=[aDecoder decodeObjectForKey:@"Channellist"];
self.filename=[aDecoder decodeObjectForKey:@"filename"];
}
return self;
}
@end