crash while removing objects from NSMutableArray

前端 未结 6 580
遇见更好的自我
遇见更好的自我 2021-01-04 00:55

In my iphone project (ARC enabled) i have a nsmuatble array which contains some 5 managed objects (which are retrieved from core data ) and in some scenario i n

6条回答
  •  误落风尘
    2021-01-04 01:13

    From the exception it's very evident that at some point you are assigning an immutable instance to your mutable array. From the comments I could make out that you were sorting surveys and sorted array was returning immutable array. Type casting will not do good for getting mutableCopy of an immutable object.

    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,nil]; 
    surveys = (NSMutableArray *) [[[NSMutableArray alloc]initWithArray:surveys ] sortedArrayUsingDescriptors:sortDescriptors];
    

    Instead of it use

    [surveys sortUsingDescriptors: @[sortDescriptor1]];
    

提交回复
热议问题