"unrecognized selector sent to instance" 对于 NSArrayI
"unrecognized selector sent to instance" for NSArrayI
我有以下代码,它给出了 NSArray 的 "unrecognized selector sent to instance" 错误。我一直无法弄清楚这一点,并且觉得我在这里缺少一些简单的东西。如果需要,我可以 post 更多。
Quote *myQuote;
NSArray *myQuotes = theSubject.quotes;
//START LOOP HERE
for (myQuote in myQuotes){
NSLog(@" excerpt = %@", myQuote.excerpt);
NSLog(@" desc2 = %@", myQuote.desc2);
NSLog(@" quote_date = %@", myQuote.quote_date);
NSLog(@" myQuote = %@", myQuote);
我认为问题出在这个 returns 引号数组的函数中:
- (NSArray *) getQuotesFromSubId:(NSInteger )subId {
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
self.quoteMaps = [appDelegate quoteMaps];
self.quotes = [appDelegate quotes];
//get the quote_ids from quote_map for this subject_id
NSString *stringOfSubjectId = [NSString stringWithFormat:@"%ld", (long)subId];
NSPredicate *filterSubjectId = [NSPredicate predicateWithFormat:@"subject_id == %@", stringOfSubjectId];
NSArray *quoteMapSection = [self.quoteMaps filteredArrayUsingPredicate:filterSubjectId];
NSMutableArray *quoteSection = [[NSMutableArray alloc] init];
NSArray *quoteToAdd = [[NSArray alloc] init];
for (QuoteMap *qm in quoteMapSection){
//get the quote_ids from quote_map for this subject_id
NSPredicate *filter = [NSPredicate predicateWithFormat:@"quote_id == %@", qm.quote_id];
quoteToAdd = [self.quotes filteredArrayUsingPredicate:filter];
[quoteSection addObject:quoteToAdd];
}
return quoteSection;
}
我就是这样称呼它的:
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *myQuotes = [appDelegate getQuotesFromSubId:selectedSubject.subject_id];
NSMutableArray *mArray = [appDelegate createMutableArray:myQuotes];
selectedSubject.quotes = mArray;
NSMutableArray *mutableArray = [appDelegate createMutableArray:myQuotes];
selectedSubject.quotes = mutableArray;
我收到以下错误
2016-02-23 00:24:20.383 Quotes[10631:3698114] -[__NSArrayI excerpt]: unrecognized selector sent to instance 0x15ebbeff0
2016-02-23 00:24:29.164 Quotes[10631:3698114] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI excerpt]: unrecognized selector sent to instance 0x15ebbeff0'
*** First throw call stack:
(0x182b55900 0x1821c3f80 0x182b5c61c 0x182b595b8 0x182a5d68c 0x100078b2c 0x1000642d0 0x187cb17f4 0x187cb1f8c 0x187b9fc90 0x187ba2e88 0x187977284 0x187883394 0x187882e90 0x187882d18 0x185259c00 0x10011dbb0 0x100123658 0x182b0cbb0 0x182b0aa18 0x182a39680 0x183f48088 0x1878b0d90 0x100040398 0x1825da8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
您正在向 myQuotes
的成员 (myQuote
) 发送 -excerpt
。运行时说 NSArray
(NSArrayI
是一个内部子类)实例无法理解 -excerpt
。
所以成员的类型是NSArray
。我们无法知道为什么数组 MyQuotes
中有 NSArray
的实例,因为我们看不到该代码。当您尝试向 quotes
属性 添加新引号并顺便添加整个数组而不是其成员时,可能会发生这种情况。
您的编辑:
这是错误的:
NSArray *quoteToAdd = [[NSArray alloc] init]; // This is an array. It identifier should be quote*s*ToAdd
// BTW: This above code is meaningless, because you do not need to create an array instance. Simply omit "[[NSArray alloc] init]". But this is not your problem.
for (QuoteMap *qm in quoteMapSection){
…
quoteToAdd = [self.quotes filteredArrayUsingPredicate:filter]; // filtered array returns an *array*
[quoteSection addObject:quoteToAdd]; // You add the *array* instead of the member of the array.
}
你得到的是一个数组。然后将数组本身( 而不是 它的成员)添加到现有数组。结果你得到一个包含数组的数组。
只需更改...
[quoteSection addObject:quoteToAdd];
…至:
[quoteSection addObjectsFromArray:quoteToAdd];
(并将参考名称更改为复数形式以提高可读性。)
我有以下代码,它给出了 NSArray 的 "unrecognized selector sent to instance" 错误。我一直无法弄清楚这一点,并且觉得我在这里缺少一些简单的东西。如果需要,我可以 post 更多。
Quote *myQuote;
NSArray *myQuotes = theSubject.quotes;
//START LOOP HERE
for (myQuote in myQuotes){
NSLog(@" excerpt = %@", myQuote.excerpt);
NSLog(@" desc2 = %@", myQuote.desc2);
NSLog(@" quote_date = %@", myQuote.quote_date);
NSLog(@" myQuote = %@", myQuote);
我认为问题出在这个 returns 引号数组的函数中:
- (NSArray *) getQuotesFromSubId:(NSInteger )subId {
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
self.quoteMaps = [appDelegate quoteMaps];
self.quotes = [appDelegate quotes];
//get the quote_ids from quote_map for this subject_id
NSString *stringOfSubjectId = [NSString stringWithFormat:@"%ld", (long)subId];
NSPredicate *filterSubjectId = [NSPredicate predicateWithFormat:@"subject_id == %@", stringOfSubjectId];
NSArray *quoteMapSection = [self.quoteMaps filteredArrayUsingPredicate:filterSubjectId];
NSMutableArray *quoteSection = [[NSMutableArray alloc] init];
NSArray *quoteToAdd = [[NSArray alloc] init];
for (QuoteMap *qm in quoteMapSection){
//get the quote_ids from quote_map for this subject_id
NSPredicate *filter = [NSPredicate predicateWithFormat:@"quote_id == %@", qm.quote_id];
quoteToAdd = [self.quotes filteredArrayUsingPredicate:filter];
[quoteSection addObject:quoteToAdd];
}
return quoteSection;
}
我就是这样称呼它的:
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *myQuotes = [appDelegate getQuotesFromSubId:selectedSubject.subject_id];
NSMutableArray *mArray = [appDelegate createMutableArray:myQuotes];
selectedSubject.quotes = mArray;
NSMutableArray *mutableArray = [appDelegate createMutableArray:myQuotes];
selectedSubject.quotes = mutableArray;
我收到以下错误
2016-02-23 00:24:20.383 Quotes[10631:3698114] -[__NSArrayI excerpt]: unrecognized selector sent to instance 0x15ebbeff0
2016-02-23 00:24:29.164 Quotes[10631:3698114] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI excerpt]: unrecognized selector sent to instance 0x15ebbeff0'
*** First throw call stack:
(0x182b55900 0x1821c3f80 0x182b5c61c 0x182b595b8 0x182a5d68c 0x100078b2c 0x1000642d0 0x187cb17f4 0x187cb1f8c 0x187b9fc90 0x187ba2e88 0x187977284 0x187883394 0x187882e90 0x187882d18 0x185259c00 0x10011dbb0 0x100123658 0x182b0cbb0 0x182b0aa18 0x182a39680 0x183f48088 0x1878b0d90 0x100040398 0x1825da8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
您正在向 myQuotes
的成员 (myQuote
) 发送 -excerpt
。运行时说 NSArray
(NSArrayI
是一个内部子类)实例无法理解 -excerpt
。
所以成员的类型是NSArray
。我们无法知道为什么数组 MyQuotes
中有 NSArray
的实例,因为我们看不到该代码。当您尝试向 quotes
属性 添加新引号并顺便添加整个数组而不是其成员时,可能会发生这种情况。
您的编辑:
这是错误的:
NSArray *quoteToAdd = [[NSArray alloc] init]; // This is an array. It identifier should be quote*s*ToAdd
// BTW: This above code is meaningless, because you do not need to create an array instance. Simply omit "[[NSArray alloc] init]". But this is not your problem.
for (QuoteMap *qm in quoteMapSection){
…
quoteToAdd = [self.quotes filteredArrayUsingPredicate:filter]; // filtered array returns an *array*
[quoteSection addObject:quoteToAdd]; // You add the *array* instead of the member of the array.
}
你得到的是一个数组。然后将数组本身( 而不是 它的成员)添加到现有数组。结果你得到一个包含数组的数组。
只需更改...
[quoteSection addObject:quoteToAdd];
…至:
[quoteSection addObjectsFromArray:quoteToAdd];
(并将参考名称更改为复数形式以提高可读性。)