我想将对象添加到 NSMutableArray 但在编写以下代码后我得到 benchmarkArray NIL。错在哪里请帮帮我
[benchmark setBenchmarkTitle:self.benchmarkTitle.text];
[benchmark setBenchmarkDescription:self.benchmarkDescription.text];
[benchmarkArray addObject:benchmark];
我的基准课程是:
@interface Benchmark : NSObject
@property (nonatomic, retain) NSString *bid;
@property (nonatomic, retain) NSString *benchmarkTitle;
@property (nonatomic, retain) NSString *benchmarkDescription;
-(id)initWithCoder: (NSCoder *)coder;
-(void)encodeWithCoder:(NSCoder *)encoder;
@end
@implementation Benchmark
@synthesize bid;
@synthesize benchmarkTitle;
@synthesize benchmarkDescription;
- (id) initWithCoder:(NSCoder *)coder {
self = [super init];
if(self) {
bid = [coder decodeObjectForKey:@"id"];
benchmarkTitle = [coder decodeObjectForKey:@"benchmarkTitle"];
benchmarkDescription = [coder decodeObjectForKey:@"benchmarkDescription"];
}
return self;
}
- (void) encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:bid forKey:@"id"];
[encoder encodeObject:benchmarkTitle forKey:@"benchmarkTitle"];
[encoder encodeObject:benchmarkDescription forKey:@"benchmarkDescription"];
}
@end