我有一个这样定义的对象:如何在我的NSMutableArray上移除另一个对象的一部分的所有对象?
#import "Scores.h"
@implementation Scores
@synthesize sentenceKey, scorrectAnswers;
+ (id)addScore:(NSString *)senKey
{
Scores *newScore = [[self alloc] initWithSentenceKey:senKey
scorrectAnswers:[NSMutableArray new]];
return [newScore autorelease];}
我想removeAllObjects我用这种方法可变数组:
Scores.h:@interface Scores : NSObject {
NSString *sentenceKey;
NSMutableArray *scorrectAnswers;
}
@property (nonatomic, copy) NSString *sentenceKey;
@property (nonatomic, copy) NSMutableArray *scorrectAnswers;
+ (id)addScore:(NSString *)senKey;
- (id)initWithSentenceKey:(NSString *)sKey
scorrectAnswers:(NSMutableArray *)scorrectAs;
- (id)initWithSentenceKey:(NSString *)sKey;
- (void)removeArrayObjects;
Score.m
- (void)removeArrayObjects;{
[scorrectAnswers removeAllObjects];}
...我从另一个程序调用这样的电话:
for (Scores *sScore in scores)
{
[sScore removeArrayObjects];
}
...当我运行它,我得到这个错误:
- [__ NSArrayI removeAllObjects]:无法识别的选择发送到实例0x53412d0
谁能告诉我,我做错了什么吗?谢谢。
感谢您非常有帮助的回应。我没有使用plist。这是我如何创建我的数组:[sentenceScore setScorrectAnswers:correctAnswers]。所以,如果我使用保留的副本,而不是在我的@property声明中,你认为这将解决我的问题? – reid55
它应该做的,但如果这是你打算采取'copy'那么你应该考虑把它当作'copy'但使用自己实现二传手'mutableCopy' –
为我工作。谢谢!! –