Replies: 3 comments 1 reply
-
Hey @m-housh!
For this reason, CoreData will not work out of the box with TCA. One way to make it working while relatively preserving CoreData performance is to model each entity as a In 2023, the only reason I find to use CoreData is to get automatic CloudKit synchronization across devices. If you don't need that and you're writing a TCA app, I'd advise using a persistence layer that relies on value types. You can check GRDB for example. |
Beta Was this translation helpful? Give feedback.
-
The more I'm digging into the problem I don't think it's with CoreData, but something is going on where my State is changing or something. The printChanges shows items are loaded, but it does not propagate to my state. However if I allow the view to load first then load items with a button, it works. I added an ID to my state and when the view appears the ID is different than the ID after it has appeared and loaded the state, which seems like unexpected behavior, however I'm not sure if this is a SwiftUI problem or not. Here's a video that shows the ID's printed to the console are different and a video that shows that the load button works once the view has appeared. Screen.Recording.2023-05-24.at.8.22.04.AM.movStrange-Behavior-TCA-Example.mov |
Beta Was this translation helpful? Give feedback.
-
hey @m-housh , I just found this post while looking for information about CoreData with TCA. I'm not sure if you've already solved that problem. The problem what I found was By the way, a warning message about dissmissing the sheet view was appeared when I ran the app, I modified some codes like below: // TodoListView.swift
...
case let .destination(.presented(.addTodo(.didSave(todo: todo)))):
state.todos[id: todo.id] = .init(todo: todo)
state.destination = nil // remove this
return .send(.destination(.dismiss))
...
// AddTodoView.swift
...
@Dependency(\.dismiss) var dismiss // add this
...
case .saveButtonTapped:
return .run { [todo = state.todo] send in
...
await send(.didSave(todo: saved))
await self.dismiss() // add this
} Lastly, if you find out the cause of this issue, please let me know, and thank you for sharing your code. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First off, I'm not very confident in my core-data skills as I've never worked with it, but I have an upcoming project that I intend to use it for. I built a toy todo application to play around with it, as well as experiment with CoreData inside a
swift-package
.I thought that I had a working example using a plain old array and a
ForEach
, however now I'm not so sure as I was deleting all the items in between my experimentation's.Anyway, my problem is that I start out with an empty array of
Todo
's then load my Entity objects in from CoreData and convert them to a struct that stores the values along with theNSManagedID
, myState
get's populated, however my view does not reflect the state although it shows they were loaded using the_printChanges()
on my reducer.All of the online examples use the
@FetchRequest
, but I'm not sure if / how to use something like that in the TCA pattern,so my dependency client object just loads the objects in and handles saving, updating, etc.
I'm not able to reproduce the problems using TCA without CoreData, so I'm ASSuming I'm doing something wrong with how I'm managing that, but at any rate I do feel it's strange behavior that the view does not change when the state changes when I'm observing the whole state. I tried using a binding on my items, a view state object to observe changes, I've also tried getting back to what I thought was a working state just using the SwiftUI
ForEach
instead of aForEachStore
, but nothing seems to be working.At any rate, here is my toy Todo's app if there are any suggestions or if anyone has any projects they can share that use CoreData and TCA together, that would be awesome. The
main
branch shows the problem when I first noticed it and uses aForEachStore
there's also afor-each
branch that was me trying to get back to what I thought was a working state prior to my refactor of using aForEachStore
.TIA.
Beta Was this translation helpful? Give feedback.
All reactions