In my Core Data project I have 2 entities "User" and "Visit" (One-To-Many rel). User <----->>Visit

In the home view of my app in the half top of the view there are a bunch of textfields to insert new users and in the half bottom of the view I have a UITableView with the users list.

Every time I insert a new User it populates the UITableView. Then if click one of the cell in my bottom UITableView it goes to another screen that is the same of the previous (half top with textfields and date picker to insert a new Visit and half bottom UITableView with visits list of a specific user).

So the first screen passes to the second one the object User of my entity.

Ho can I get all the visits of that specific user to populate the UITableView? What do I have to set in the predicate?

有帮助吗?

解决方案

Your "Visit" entity should have a (to-one) relationship "user" to the "User" entity. Then you can simply execute a fetch request on the "Visit" entity with the predicate

[NSPredicate predicateWithFormat:@"user = %@", selectedUser]

Consider also to use a NSFetchedResultsController which is convenient to populate a table view.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top