'Setting core data value to @ State
I am fetching the user's cached data from coreData
@FetchRequest(sortDescriptors: []) var userData: FetchedResults
I have a field
@State var bio:String = ""
This variable stores the user input into the field, so I cannot just use userData directly to display the cached value for bio.
How do I initialize bio with the value userData[0].bio?
Solution 1:[1]
You can set it in .onAppear() as the fetch request will have been performed by then and the variable available. There may be other ways, but you did not give enough code to suggest any.
.onAppear {
bio = userData[0].bio
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yrb |
