How To Preload Data Into SwiftData ModelContainer ⚡️ | SwiftData Tutorial | #5

preview_player
Показать описание

Easily Preload SwiftData On Your App’s First Launch ⚡️

Build A To-Do List App using SwiftData (Swift Data Tutorials)

**********************************

*Timestamps:*

00:00 - Intro
00:25 - Building Our Categories Model
01:55 - Creating A Custom Model Container
07:09 - Using Your Own Custom Container In SwiftData
09:02 - Pre-Filling Data On App Launch SwiftData

**********************************

In this SwiftData tutorial, we'll look at Pre-filling A SwiftData ModelContainer within our To-Do list app. We'll see how to easily preload SwiftData on your app's first launch. By adding some default categories that a user can choose from.

**********************************

*Check Out My Courses 👨🏽‍🏫*

Enjoy my teaching style? Check out my other courses on my website that may interest you, they range from beginner to advanced topics within iOS development.

*Link to Website*

**********************************

*Join the crew 🤝*

Want to help support the channel? Become a member with the join link below and get access to exclusive badges and stickers, as well as other perks that are coming soon.

*Become a channel member*

*Support in other ways 💕*

You can support me for free and help the channel grow so that I can continue to make the best iOS development content for you by liking, commenting, subscribing, and hitting the notification bell.

All of this really helps my channel grow and allows me to keep on making content for you. If you’re interested in subscribing to the channel then you can do so with the link below.

*Subscribe to the tundsdev YouTube channel*

**********************************

*Download Source Code*

Interested in looking at the source code? Then check out the GitHub Repo below

**********************************

EditorKeys
View Editor Keys Amazing Products with the link below and use the discount code for 10% off any product

Get a 10% Discount Code on any product with the code below
TUNDSDEV

See my keyboard cover in action with my review below 👇🏾

**********************************

RØDE Wireless Mic

RØDE SmartLavPlus Microphone

2021 Apple MacBook Pro (16-inch, Apple M1 Pro chip with 10‑core CPU and 16‑core GPU, 16GB RAM, 1TB SSD) - Space Grey

Apple Magic Keyboard with Numeric Keypad (Wireless, Rechargeable) 

Apple Magic Mouse

Secretlab TITAN 2020 Charcoal Blue Gaming Chair

ErgoFoam Ergonomic Foot Rest for Under Desk

Lumbar Support Pillow

Macbook Stand for Apple Macbook and All Notebooks

Portable Chair Green Screen Background

**********************************

#iosdev #iosdevelopment #swift #swiftlanguage #xcode #appdevelopment #mobileappdevelopment #iosappdevelopment #appdeveloper #iosprogramming #iosengineer #appdevelopmenttips #iosdevelopmenttips #swiftui
Рекомендации по теме
Комментарии
Автор

Nice way you showed us to add default data at app launch. Thank you.

nileshjdarji
Автор

You are a lifesaver dude!
This solved my whole problem!

chezchezchezchez
Автор

Here we have some really helpful stuff, appreciated Tunds 🙆🏻‍♀

tech_ch
Автор

Nice set of videos, thanks. Is it possible to pre-load data with a relationship? In your example can you import a to do that already has a category assigned?

corey
Автор

Great stuff! Would be cool to see repeatable daily, weekly, monthly, yearly tasks.

dmitrygolovin
Автор

Great work tunds! My question is how would you do this to have some preloaded toDos? Would you have to create the extension on the toDoItem and then init each one?

Ride
Автор

Is there a reason you used actor ItemContainer but in the preview lesson you just used a struct?

NICKLIFE
Автор

This video let me to you and I’m subscribed and plan to watch several. Great job on these!! I am new to SwiftData and this video helped me realize that I can create a class and initiate in App and inject it into the views. But I cannot figure out how to create a reference to the ItemsContainer outside a View. In my app, I need to call an API and pass JSON, but can’t get to the SwiftData model to create it within my class that calls the API. Have you covered this in any of your videos?

PaulSmithGainesville
Автор

What if you had a model thats unrelated to the other models how would you specify that modelContainer

milanlabus
Автор

Hi Sir, what if i use this method to store the data, for the next version of my app, i want to add more preload category, how can I do it?

lfan_tv
Автор

Great video! I have a question. My data preloads correctly, however now when I go to make a new "category" it does not save. If I delete a default category it will update and remove it but it seems like anything outside of the default data now does not get saved. It did before this, and if I don't use the ItemsContainer and just do it like before then everything works fine. Any idea?

DefeatOG
Автор

This is really well done! Thanks so much for this great instruction.
I am stuck trying to safely unwrap the container. Is there a way to return a default ModelContainer?
Thanks!

holycrosscv
Автор

yours videos are awesome, with good examples😂

Alan-ucpf
Автор

Very good series of videos. Pre-filling a small amount of data works great. What about when you have a large json file of data you would like to pre-fill to SwiftData. Obviously this works but the app sits with a blank screen while this happens. Thoughts on how to show some sort of progress view? Challenging because you don't use .onAppear or .task in the ContentView where one could display a progress view.

NormNorris
Автор

As always nice work. I wonder if you could set this up based on a query instead of a boolean. If the query/fetch returned empty, you could then prepopulate with categories. Thanks for the great video and education.

cloftis
Автор

Great video Tunds. Really helped me. I'm now working on making the once only set up (i.e. create categories) work across multiple devices. Thinking of turning the @appstorage firstRun property into a ubiquitous key value pair. Any tips?

grin_phi
Автор

How about pre-populating SwiftData with a huge data from an sql file? Checking on the docs I don't think SwiftData can do it out-of-the-box. How would you suggest to do it? Use Core Data?

finchicoph
Автор

Great video.
I have a question can we use switData in a UIKit project ?
Thanks

AliouSARR
Автор

Beta 8 errors when it tires to create the ModelContainer. "Cannot convert value of type 'ModelConfiguration' to expected argument type 'any PersistentModel.Type'" Same error for schema. Any clue what is going on?
Thanks!

holycrosscv