NSMutableArray removeObjectAtIndex: throws invalid argument exception

前端 未结 3 816
不知归路
不知归路 2021-01-18 05:41

I\'m writing an application to show some news from a portal. The news are fetched using a JSON file from the Internet and then stored into a NSMutableArray using the CoreDat

3条回答
  •  梦毁少年i
    2021-01-18 06:22

    Your NewsFetcher returns you an immutable array, not a mutable instance. Use the following instead for initialization:

    NSArray *results = [[NewsFetcher sharedInstance] 
                         fetchManagedObjectsForEntity:@"News" 
                         withPredicate:predicate
                         withDescriptor:@"Titolo"];
    dataSet = [results mutableCopy];
    

    An expression like A *a = (A*)b; only casts the pointer to a different type - it doesn't convert/change the actual type of the instance it points to.

提交回复
热议问题