Filtering array of objects using predicate crashes on iOS 9 and 10 devices

182 Views Asked by At

I have the following code to remove all objects having 'sever' value equal to -1. My code is as follows:

NSMutableArray *sortedArray = [[NSMutableArray alloc] initWithArray:self.allInteractions];
//Removing all interactions with severity equal to -1
NSPredicate *severityPredicate = [NSPredicate predicateWithFormat:@"sever != %@", @-1];
[sortedArray filterUsingPredicate:severityPredicate];

This is working fine on iOS 11 device and simulators. It is working good on iOS 9 and 10 simulators as well. But when I tried installing it on iPad(iOS 9.2) and iPhone 5 (10.3.3), it crashes with:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x918038d0)

and also displays the following warning on console:

warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.

I can't figure out what is going wrong here.

UPDATE

I've enabled zombie objects and it logs

[CFNumber isEqual:]: message sent to deallocated instance 0x18d0b0b0

self.allInteractions is an array of the following class:

@interface Interaction : NSObject

@property (nonatomic, strong) NSString *class1;
@property (nonatomic, strong) NSString *subject;
@property (nonatomic, strong) NSString *object;
@property (nonatomic, strong) NSString *details;
@property (nonatomic, assign) NSNumber *sever;
1

There are 1 best solutions below

0
On BEST ANSWER

I was finally able to sort out this issue. It was not related to predicate even though it crashed during the implementation of filtering using predicate. In the Interaction model, sever property was assigned as (nonatomic, assign) and replacing assign to strong like the other properties fixed this issue.

@interface Interaction : NSObject

@property (nonatomic, strong) NSString *class1;
@property (nonatomic, strong) NSString *subject;
@property (nonatomic, strong) NSString *object;
@property (nonatomic, strong) NSString *details;
@property (nonatomic, strong) NSNumber *sever;

Assign was working good in iOS 11 but in lower versions, deallocations can happen using assign.