崩溃与循环,看起来在一个可变数组

时间:2016-03-16 13:38:06

标签: ios objective-c

当我尝试使用for循环来查看名为endpoints的NSMutable数组时,我的应用程序出现问题。为了快速解释该程序,我有一个类从API收集URL的不同端点并创建一个关联视图。下面的代码显示了我使用这些端点的部分(有时我只有一个用于视图,但我可以有更多用于其他视图)

所以这是有问题的部分(当我启动应用程序时崩溃)

- (void)viewDidLoad {
    [super viewDidLoad];

    _scheduleList = [[NSMutableArray alloc] init];
    _futurScheduleList = [[NSMutableArray alloc] init];
    _currentScheduleList = [[NSMutableArray alloc] init];
    _pastScheduleList = [[NSMutableArray alloc] init];


        for (id item in self.endpoints) {
            NSString *url = [NSString stringWithFormat: @"https://apis.is%@", item];
            NSData *JSONData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
            // Parse JSON
            NSError *error;
            if (JSONData) {
                NSDictionary *json = [NSJSONSerialization
                                      JSONObjectWithData:JSONData //1

                                      options:kNilOptions
                                      error:&error];
                NSArray *jsonResult = [json objectForKey:@"results"];
                for (id item in jsonResult) {
                    TVShow *tvs = [[TVShow alloc] init];
                    tvs.title = [item objectForKey:@"title"];
                    tvs.startTime = [item objectForKey:@"startTime"];
                    tvs.duration = [item objectForKey:@"duration"];
                    tvs.episode = [item valueForKeyPath:@"series.episode"];
                    tvs.serie = [item valueForKeyPath:@"series.series"];
                    tvs.theDescription = [item objectForKey:@"description"];

                    if ([self isItAFuturShow:tvs]) {
                        [_futurScheduleList addObject:tvs];
                    }

                    if ([self isItAPastShow:tvs]) {
                        [_pastScheduleList addObject:tvs];
                    }

                    if ([self isTimeForAShow:tvs]) {
                        [_currentScheduleList addObject:tvs];
                    }

                    [_scheduleList addObject:tvs];
                }
            }
        }
    }

当我看到错误时,我有:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xa00f048fc1508fc8'

当我检查0xa00f048fc1508fc8时,我有内容

此行for (id item in self.endpoints)

处弹出错误

感谢您的帮助

0 个答案:

没有答案