This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi all,
I've spent hours on this issue and can't figure it out. All the code I've looked up seems to be exactly the same as what I've written, but my code keeps crashing during runtime.
I have two entities. The Item entity has a one-to-many relationship with the Tasks entity. The Item object is passed into the view as an ObservedObject. I want to load all the Tasks that are linked to that specific item.
@ObservedObject var item: Item
@FetchRequest var tasks: FetchedResults<Tasks>
init(item: Item) {
self.item = item
var predicate: NSPredicate?
predicate = NSPredicate(format: "item == %@", item)
self._tasks = FetchRequest(entity: Tasks.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \Tasks.desc,
ascending: false)],
predicate: predicate)
}
From what I've checked, I believe I have the entities/relationships set up properly. I've tested the predicate with a matching string and it loads perfectly fine. But when I use item as the predicate, I get a runtime error.
--> Thread 1: "keypath item not found in entity Tasks"
Am I missing something here? I understand the concept of the predicate when it comes to filtering out via a property name etc, but what I'm attempting here is definitely giving me some trouble. Hopefully someone has some insight.
Thanks in advance!!
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/swift/comme...