ios - fetch any data that contain ID core data -
how fetch these datas
[account1, account3]
in
[account1, account2, account3, account4, ..] (id entity)
with account1 & account3 id
i tried below code, got random account, not specific account 1 , account 3.
var ids = [account1id, account3id] let fetchrequest: nsfetchrequest<accounts> = accounts.fetchrequest() let titlesort = nssortdescriptor(key: "type", ascending: true) fetchrequest.sortdescriptors = [titlesort] fetchrequest.predicate = nspredicate(format: "any %@ in id", argumentarray: ids) var controller: nsfetchedresultscontroller<accounts> if #available(ios 10.0, *) { controller = nsfetchedresultscontroller(fetchrequest: fetchrequest, managedobjectcontext: context, sectionnamekeypath: nil, cachename: nil) } else { // fallback on earlier versions controller = nsfetchedresultscontroller(fetchrequest: fetchrequest, managedobjectcontext: contexts, sectionnamekeypath: nil, cachename: nil) } { try controller.performfetch() let tes = controller.fetchedobjects! print("check: \(tes.count) \(tes)") } catch { let error = error nserror print("\(error)") }
try this:
var ids = [id1, id2] fetchrequest.predicate = nspredicate(format: "any %k in %@", argumentarray: [id, ids])
Comments
Post a Comment