I'm trying to take an array that came from a plist, and use that strings to know if they already exists in the context.
But this error is happening
reason: '-[__NSCFArray isEqualToString:]: unrecognized selector sent to instance
here is the code..
- (NSArray*)loadPlist
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"AlreadyDownloaded" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *plistArray = [[NSMutableArray alloc] initWithArray:[dict allValues]];
return plistArray;
}
-(void)writeToList:(NSArray *)text
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"AlreadyDownloaded" ofType:@"plist"];
NSArray *copy = [self loadPlist];
NSMutableArray *list = [copy mutableCopy];
[list addObjectsFromArray:text];
NSArray *array = [[NSArray alloc] initWithObjects:@"ObjectsIDS", nil];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
for(NSString *ob in list)
{
[dict setValue:ob forKey:@"ObjectsIDS"];
}
[dict writeToFile:path atomically:YES];
}
-(bool)compareIDS:(NSString *)text
{
NSArray *copy = [[NSArray alloc]initWithArray:[self loadPlist]];
NSMutableArray *list = [copy mutableCopy];
NSMutableString *st = [[NSMutableString alloc]init];
for(NSString *ob in copy)
{
if([ob isEqualToString:text])
return YES;
}
return NO;
}
Thank you guys!
Best Regards.
从崩溃日志中,我们怀疑NSString * ob是一个数组,而不是NSString,最好在对象ob的for(NSString * ob in copy)处设置一个断点。
Use
NSArray indexOfObject Method:
return [copy indexOfObject:text] != NSNotFound
or
for(int i = 0; i < copy.count; i++) {
if([(NSString *) [copy objectAtIndex:i] isEqualToString:text]) return YES;
}
return NO;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.