Swift nested filter optimization?

前端 未结 2 1343
迷失自我
迷失自我 2021-02-10 01:58

I was trying to do something in Swift that would be easy in Objective-C using KVC. The new Contacts framework added in iOS9 is for the most part easier to use than the old Addr

2条回答
  •  鱼传尺愫
    2021-02-10 02:28

    I'm guessing you're wanting a more swift-y way, but obviously anything you can do in Obj-C can also be done in swift. So, you can still use NSPredicate:

    let predicate = NSPredicate(format: "ANY phoneNumbers.value.digits CONTAINS %@", "1118675309")
    let contactNSArray = contacts as NSArray
    let contactsWithJennysPhoneNumber = contactNSArray.filteredArrayUsingPredicate(predicate)
    

提交回复
热议问题