File DataPersistence in SwiftUI
HTML-код
- Опубликовано: 13 окт 2024
- This is the second video of the SwiftUI ToDo App series where we are building an ToDoapp from scratch in SwiftUI and then will refactor it to use the Combine Framework. In this video we will be building our data persistence layer. We will using the Codable protocol in Swift to encode and decode our data so that we can save and restore our list of ToDos from a file stored in our app's documents directory.
If you want to support my work, you can buy me a coffee :)
ko-fi.com/stew...
******* Download my StewartLynch RUclips Channel Application - Free **********
stewartlynch.g...
Starter Files (Completed project from the previous video):
www.createchsol...
Completed Project for this video:
www.createchsol...
All Tutorials in this series
Introduction:
• Not another SwiftUI To...
1. Building the ToDo App in SwiftUI
• Building the ToDo app ...
2. Data Persistence
• File DataPersistence i...
3. Meaningful Error Handling
• Responsible Error Hand...
4. Combine: PassthroughSubject and .sink
• Combine PassthroughS...
5. Combine: Just and @Published PropertyWrapper
• Combine @Published pro...
6. Combine: CurrentValueSubject
Coming April 29
Other references made in this video:
A Better Result
• A Better Result
Other References:
Stewart Lynch's RUclips Channel:
/ stewartlynch
Stewart Lynch on Twitter:
/ stewartlynch
CreaTECH Solutions Website:
www.createchso...
Stewart Lynch's GitHub:
github.com/Ste...
Thank you so much Stewart...
Hahaha, during my Swift education I was mostly supposed to work in Firebase or Coredata, while it ALWAYS has been nothing more, than 10-30 variables with zero optimization)) Thanks for pointing out this overkill business here)))
I don't know if this question is appropriate for this video or project, but would this work where you could choose to save the json file say in your documents folder so that the json data could be used in another app? For example, I have an idea where I make an app to create a json file that contains a bunch of events with times and places. This json file would then be placed on a server that a person could use an app to get what events are upcoming. And the json file could be updated as new events take place.
Yes, this is possible. Check out this article nemecek.be/blog/6/saving-files-into-users-icloud-drive-using-filemanager
@@StewartLynch Thanks. Will look into that more when I complete this series
@@ThePhotodiver Keep in mind that if you use CloudKit this way, you can't transfer (sell) your app to another company. (Thanks Apple!)
One way around this is to send the file to a server. Then you can control access to that file from other apps, web apps.
@@w0mblemania Thanks. That is what I have in mind. I will need the file to be on a separate server. It is still good to learn about the iCloud link above though.
Thank you for the video!
For the func docExist part, can I write in the way below:
func docExist(docName: String) -> Bool {
let url = Self.docDirURL.appendingPathComponent(docName)
return fileExists(atPath: url.path)
}
What is the use of "named"?
Yes, you could, I use an extra argument name because I think it reads better in the caller. When you call it, it looks like docExist(named: "Some Name") rather than docExists(docName: "Some Name"). Alternatively, you could also use func docExist(_ docName: String) -> Bool { and in this case, the call would be docExists(“Some Name”). It is just a matter of style.
@@StewartLynch Thank you so much! Good to hear that it is about style. I think writing style is so important because it helps me to learn deeper and easier if I can do some slight adjustments which make me feel comfortable.
Must be Spring time. AaaaaaaaChooooooo! 😀
thx u