I am trying to predicate the nested objects value here is a structure of nested objects.
@interface APContact : NSObject
@property (nullable, nonatomic, strong) NSArray <APPhone *> *phones;
@end
@interface APPhone : NSObject
@property (nullable, nonatomic, strong) NSString *number;
@end
I am trying to predicate like this as show in below block of code.
I want to predicate the number string. how to do this
for (APContact *contact in duplucateDataArray) {
NSMutableArray *countArray = [[NSMutableArray alloc] init];
NSPredicate *morningAttendees = [NSPredicate predicateWithFormat:@"SELF.%K.%K MATCHES %@",@"phones[0]",@"number", contact.phones[0].number];
NSArray <APContact*> *predicateContact = [duplucateDataArray filteredArrayUsingPredicate:morningAttendees];
NSLog(@"predicate contact%@",predicateContact);
}
On running above code getting below exception
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<APContact 0x2824da6d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key phones[0].'
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object (
"+91 88815 12534"
).
Any suggestions would be more appreciated.