Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

1
FetchResult using one-to-many relationship not working.
Post Flair (click to view more posts with a particular flair)
Post Body

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!!

Author
User Disabled User Suspended
Account Strength
0%
Disabled 8 months ago
Suspended 9 months ago
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
55
Link Karma
5,091
Comment Karma
27,325
Profile updated: 5 hours ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago