Search / retrieve single value from one to many relationships Core Data Swift -


my data design allows 1 user have many votes; , each single record can have many votes. i'm struggling massively referencing , searching specific element relying on these

enter image description here

in master view controller, i've fetch controller on record entity, , single var user entity (ie. device-user) inserted same managedcontext.

assuming ok, when preparing segue detailed view controller, want pass in selected record (no problem); array of votes record (i think no problem, code below); , (here's tricky part) optional device-user's vote record (this question).

let votesasset = record.votes controller.votes = votesasset?.allobjects as? [vote]  let predicateforusersvote = nspredicate(format: "record.votes.user == user") let thisusersvoteforthisrecordasset = votesasset?.filteredsetusingpredicate(predicateforusersvote)                  controller.thisusersvote = thisusersvoteforthisrecordasset!.first as? vote 

what i'm trying iterate through user's votes in core data 1 record's user matches device-user.

since predicate operating on set of votes record, can use user property directly. must substitute in correct value device-user, eg:

let predicateforusersvote = nspredicate(format: "user == %@", device-user) 

the result of applying predicate set set, think may need use .anyobject() rather .first relevant vote object.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -