|
Hi, I have managed to add the core data into the application with some help. Everything that end seems to be working just fine, but I am now getting an error when I run the app & try to click a user to go into the detail view:
I truly am not sure why this is, as the link looks correct & I am a tad lost as to where it went wrong? The entities are setup with contrained id's. Friends are set through the relationship (to many) & I have checked all the attributes are spot on. Here is my content view:
My user detail view:
& my cached user file as I am guessing this may be of inportance.
Thanks in advance for any advice. |
|
Hi! Not sure if this is the reason but I think you forgot to add cachedFriend to cachedUser...
|
|
Though actually in your extension to This line
to this
your friends is not a string but a set. and in any case you have to add your friends as indicated in the post above otherwise friends prorperty will be empty : ) |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Thanks for this, I did have it written down to add as per Pauls instructions when I got stuck, but I couldn't work out where it points as there is no ".addToFriends" mentioned anywhere else in the cachedUser? Apologies if I'm missing something obvious, not feeling well at the minute and the brain fog is something else ha ha. |
|
It took me sometime to realize how it works ))) too many things happen behind the scenes. When you generate code manually via Xcode menu bar, choose Editor > Create NSManagedObject Subclass. XCode adds this code, if i am not mistaken.
you can read more here https://developer.apple.com/documentation/coredata/modeling_data/generating_code But even if you have it generated automatically by xcode, without creating those files manually, you still have access to those methods. As it still generated behind the scenes :) So if you did not delete those lines added by XCode you will be able to access them. |
|
Thank you so much. I thought I was going crazy as I was getting the error that no member "addToFriends" exists...I did the Xcode menu bar, choose Editor > Create NSManagedObject Subclass at the beginning and didn't delete any code in that file so I have no clue why it wasn't there?! The extension was there but completely empty. How strange. Thank you so much for your help! Big sigh of relief (until tomorrows code that is ;) ) |
|
You know, I suspect that when manually generating code you had this line set up as String not Set
Again, as far as I can recall this part of code marked as
relates to Relations in your core data model. i.e. if there are no relationship setup, this part won't be generated... and you had it as string... PS Check in your data model that you have CachedFriend entity -> Relationship: user, in Inspector Pane -> Type: To One And CachedUser entity -> Relationship: friends, in Inspector Pane -> Type: To Many |
|
Yes I think I did have friends set up as a string to begin with, generated the code, then remembered to set the relationship...doh This makes total sense now. Worked out I was having an allergic reaction whilst doing this challenge earlier, a miracle I wrote any code lol |
|
|
|
oh yeah, doing much better now thanks. I have gastro & allergy conditions that make me have allergic reactions fairly often. Grew up with it so very used to it, even if it still annoys the hell out of me when i'm trying to concentrate on code ha. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.