Post

Replies

Boosts

Views

Activity

Reply to saving Int array as attribute in a CoreData entity
Thanks Zimmie, DMG. It did work after adding the NSSecureUnarchiveFromData to the transformer field. (Shouldn't Xcode have a dropdown with the built-in custom-classes in there? Not very discoverable, otherwise.) Zimmie, DMG: I have a follow-up if you even happen to see this. I don't think I need to upload the code to ask the question. Let me try. my try? moc.save() statements (I did change them to do/catch eventually while trying to debug) were in a non-view file where the class dealing with the data that needed to be saved lived, and was transferred to core data through a method part of that class. The class had "@Environment(.managedObjectContext) var moc" in there, and the app compiled fine. The app did compile, but the data wouldn't save in core data. Eventually I figured out it that the try save.moc spat the error "The operation couldn’t be completed. (Foundation._GenericObjCError error 0.)". Googling that wasn't too productive either, but something I saw made me try to put all of the method code into the appropriate button within the view that called for that method (it's quite a bit of code). That, somehow, worked. My question: why? It does work, but my code looks even uglier than my usual *****. I would love to move that to the class in a separate file. Thanks a ton.
Jun ’22
Reply to saving Int array as attribute in a CoreData entity
Dude, thank you SO much! You saved me days of floundering cluelessly. I did have PersistenceController injected into ContentView exactly as you describe. For some reason, in the ViewModel I needed to make the "p" capital as in "moc = PersistenceController.shared.container.viewContext". I'm only mentioning this to help another clueless soul like me that might end up looking at this thread. You made my code way less emetic, and I thank you again for that. a.
Jun ’22
Reply to Displaying Core Data entity in Table (iOS 16)
Don Nissen, you the person! It actually works! Thank you, thank you, thank you. I was failing bad, and trying to use a dynamic fetch request thing I saw on the invaluable Hacking with Swift, but I wasn't happy with the solution, since it necessitated refetching every time a reordering is called, which seems wasteful. Am I correct in parsing what you do as transferring the core data entity (whatever thing that is) into an array (which is what I hoped a core data entity should be)? The only sad I have is that I need to make a second file to achieve that. Tried to do everything in the same file unsuccessfully. Thanks again. I haven't seen anyone with a solution to this. I don't understand how it's not a more prevalent problem for more people. I even did an "Ask Apple" office hour appointment, and their solution was to refetch, which I don't see how that is not hacky within a table. Anyways, thanks Don Nissen.
Dec ’22