Domanda

Doing a project on addressbook kind of app. I need to predicate address book contacts, result looks like this

(
{
AddressKey =     (
);
Email =     (
);
"JobTitle_Name" = "";
"Organisation_Name" = "";
Phone =     (
            {
        phoneNumber = "+919502266633";
        "phone_type" = home;
    },
            {
        phoneNumber = 9703570333;
        "phone_type" = work;
    },
            {
        phoneNumber = 91234512345;
        "phone_type" = iPhone;
    },
            {
        phoneNumber = 91239123;
        "phone_type" = mobile;
    }
);
"first_name" = Raviraja;
imageKey = "";
"last_name" = "";
serialNumberKey = 53;
source = Device;
}
)

Need to predicate the array using phoneNumber key. I tried this one

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY %K == %@",@"phoneNumber",[NSString stringWithFormat:@"%@",str]];
        NSArray *array = [contactsArray filteredArrayUsingPredicate:predicate];

but not working eventhough phone number is matching.

Help me out guys.

È stato utile?

Soluzione

The key path is wrong, it should be

[NSPredicate predicateWithFormat:@"ANY %K == %@",@"Phone.phoneNumber", ...]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top