I'm sorry I'm new to iOS development,this day I encountered a strange problem: when I remove object from custom object , it always return crash:
reason: '-[__NSArrayI removeLastObject]: unrecognized selector sent to instance
the following code:
@interface Base : NSObject
@property (nonatomic, assign) BOOL isFinish;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *subTitle;
@property (nonatomic, strong) NSString *tagURL;
@property (nonatomic, assign) NSInteger taskScore;
@property (nonatomic, assign) BOOL inProgress;
@property (nonatomic, assign) NSInteger nowTime;
@property (nonatomic, assign) NSInteger totalTime;
@end
then I use on another class:
@property (nonatomic, strong) NSMutableArray *arr1;
@property (nonatomic, copy) NSMutableArray *arr2;
_arr1 = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) {
Base *b = [[Base alloc] init];
b.title = [[NSString alloc] initWithFormat:@"%d", i];
[_arr1 addObject:b];
}
self.arr2 = [_arr1 copy];// 001, I tried copy or mutable copy
[_arr2 removeLastObject]; //it always crash in here!!
So I look through some reference,some told me must conform nscopying or nsmutablecopying protocol
So I add some method in the Base class @implementation
- (id)copyWithZone:(struct _NSZone *)zone
{
Base *copy = [[[self class] allocWithZone:zone] init];
if (copy) {
[copy setIsFinish:[self isFinished]];
[copy setTitle:[self title]];
[copy setSubTitle:[self subTitle]];
[copy setTagURL:[self tagURL]];
[copy setTaskScore:[self taskScore]];
[copy setInProgress:[self inProgress]];
[copy setNowTime:[self nowTime]];
[copy setTotalTime:[self totalTime]];
}
return copy;
}
But it doesn't work , can some one help me?