如果我愿意在你的地方,我将创建一个自定义类,它封装了如下所示的类。
任务管理器.h
#import <Foundation/Foundation.h>
@interface TaskManager : NSObject
@property(nonatomic,retain)NSMutableArray *taskList;
-(void)addTaskList:(NSMutableDictionary *)object;
@end
@interface Task : NSObject
@property(nonatomic,retain)NSMutableDictionary *taskDetails;
-(void)setTaskDetailsWithKey:(NSString*)key withValue:(NSString*)value;
@end
任务管理器.m
#import "TaskManager.h"
@implementation TaskManager
@synthesize taskList;
-(id)init
{
self = [super init];
if (self) {
if(!taskList)
taskList = [[NSMutableArray alloc] init];
}
return self;
}
-(void)addTaskList:(NSMutableDictionary *)object
{
[taskList addObject:object];
}
@end
@implementation Task
@synthesize taskDetails;
-(id)init
{
self = [super init];
if (self) {
if(!taskDetails)
taskDetails = [[NSMutableDictionary alloc] init];
}
return self;
}
-(void)setTaskDetailsWithKey:(NSString*)key withValue:(NSString*)value
{
[taskDetails setObject:value forKey:key];
}
@end