Swift Data Relationships 🚀 | SwiftData Tutorial | #2

  Рет қаралды 10,758

tundsdev

tundsdev

Күн бұрын

Пікірлер: 59
@tundsdev
@tundsdev Жыл бұрын
⚠ The crash at 9:41 is a known issue & has a workaround also by calling modelContext.save() after the deletion of an item
@tundsdev
@tundsdev Жыл бұрын
Starting from Xcode 15 Beta 6 You’ll need to specify the delete rule parameter in the Macro i.e @Relationship(deleteRule: .nullify)
@chezchezchezchez
@chezchezchezchez Жыл бұрын
@@tundsdev how do we upgrade our beta five to beta six? Thanks.
@tundsdev
@tundsdev Жыл бұрын
You can either download a new beta from Apple Developer or use a handy app i’ll have a video on soon called xcodes.app which lets you manage different versions 👌🏾
@marcaupont9145
@marcaupont9145 Жыл бұрын
Solid tutorial and great explanations!! 💪🏾💪🏾
@tundsdev
@tundsdev Жыл бұрын
Glad you liked it!
@SiamakAshrafi
@SiamakAshrafi Жыл бұрын
Thanks. Very helpful.
@tundsdev
@tundsdev Жыл бұрын
Glad it was helpful!
@michanierebinski1423
@michanierebinski1423 Жыл бұрын
A great follow up
@tundsdev
@tundsdev Жыл бұрын
Thanks 👌🏾
@jayelevy
@jayelevy Жыл бұрын
One additional comment on this and I’m reluctant to share as I’m grateful for what you do! Having said that, the coding for this is confusing if you are following these videos in sequence. I completed the first video and then moved on to this. I assumed I could simply continue with the code base as we left at the end of the last video. Wrong assumption. I kept finding pieces of code that were either missing or changed from the first video. Finally realized during the segment when you added the save function that I’m missing a bunch of code. I need to scrap and start over using the git samples for this video. I think this could be explained better. I feel it is a logical progression to move from one video to the next while continuing the same project. I hope that makes sense.
@tundsdev
@tundsdev Жыл бұрын
Hey, I’m pretty sure I reference that this video is built on top of a previous one and is part of a course 😅 (Yep I do in the intro section & warning section) I highly suggest following the entire playlist/course which you can find a link to below kzbin.info/aero/PLvUWi5tdh92wZ5_iDMcBpenwTgFNan9T7&si=DREJdYaDgntH0tEo
@jayelevy
@jayelevy Жыл бұрын
Thanks for the follow-up. That is exactly my point. That is, if you are following along in sequence on the playlist, as I was, one would assume that the ending status of code in the prior video (eg, ContentView or CreateTodoView at the end of video 1) would be equivalent to the starting point when the next video (1:many relationships) starts. That is not the case and the continuity is lost. After I finish video 1, I need to figure out the delta’s for the starting point for video 2. Maybe I am missing something. Again, not complaining!! I’m super grateful for what you do. You do an awesome job explaining things. I love it. Just sharing what seems to be a confusing transition between vids. I’ll leave it alone now. I know what to expect! It’s all good… thanks again for your service to the SwiftUI community!! Cheers
@tundsdev
@tundsdev Жыл бұрын
@@jayelevy I’m not too sure what else to here, for every video in this course. I provide starter files and final files in my GitHub repo so you can easily pickup and follow along. The only way around this is if I created a long video with everything combined which would be huge. Maybe i’ll start making it extra clear in my vids that you’ll need to watch previous videos and or get the starter files from GitHub to avoid confusion 👌🏾 Because it is meant to flow between videos where you can pick stuff up, i think the problem here is that its not clear that you can use the starter files to dive into the code straight away
@jayelevy
@jayelevy Жыл бұрын
Thanks for your responses. Now… I need to get back to the videos!! 🍻
@nileshjdarji
@nileshjdarji 4 ай бұрын
super awesome video. Love it.
@mrchumley
@mrchumley Жыл бұрын
Thanks for the video! Brilliant tutorial, but is there something missing just before 8:10? I couldn't see where you added the new buttons to the main view?
@tundsdev
@tundsdev Жыл бұрын
Thanks and if you keep watching to when I save data you’ll see the SwiftUI code, also the final code is in the description box too. Since I wanted to keep this vid short 👌🏾
@mrchumley
@mrchumley Жыл бұрын
Fair enough and yes, I picked it up from your GitHub - thanks for sharing 🙂
@mkhasson97
@mkhasson97 Жыл бұрын
Nice video, could you perhaps complete the serie and add many to many relationships too? For example let's say insert sub-todo or I mean list into this list, I will really appreciate that. Thank you so much ❤
@tundsdev
@tundsdev Жыл бұрын
Thanks for the idea! That would still be a One to many relationship, for many to many a tags functionality would work for that 👀
@aplutalobacz
@aplutalobacz Жыл бұрын
@@tundsdevhow do we implement 2 models when one consists an array of other model. Imagin tag could have different variables and then ToDo event can consist an array of them? I have been trying to create this type of database- unfortunately without success:(
@Echaront
@Echaront 5 ай бұрын
In Xcode 15.4, I am encountering errors at 7:05. The error reads: "Struct 'ViewBuilder' requires that 'EmptyTableRowContent' conform to 'View'" and Static method 'buildExpression' requires that 'TextField' conform to 'TableRowContent'. It would be great if you could update the app using Xcode 15.4 for iOS 17.
@tundsdev
@tundsdev 5 ай бұрын
Hey can you download the final source code in the description box, i've ran project and the only thing that needs to be removed is the .nullify since there's no need to specify this anymore and also it's worth noting that this video was created when xcode 15 and swiftdata was still in beta.
@Echaront
@Echaront 5 ай бұрын
@@tundsdev fair enough. Thank you for your amazing content!
@edfrazier
@edfrazier 2 ай бұрын
I tried to change the code a bit to extract the actual toDoCell from the contentView into its own view. Everything works fine except when i delete a category the content view doesn't refresh and remove the category like it does in the original code. Can this not be done like that?
@bobgilmore3224
@bobgilmore3224 Жыл бұрын
As of Xcode 15 beta... 4? 5?, the @relationship macro requires a deleteRule tag, i.e., at 5:01, you need... @Relationship(deleteRule: .nullify, inverse: \Category.items) (I just noticed that this is mentioned in the comment regarding the crash at 9:41, but I wasn't even looking at that that since I was seeing problems at 5:01.)
@tundsdev
@tundsdev Жыл бұрын
👋🏾 yep both are mentioned in the pinned comments, i filmed this video using Xcode 15 b1 the delete rule changes were made from b6
@josephestrada4222
@josephestrada4222 7 ай бұрын
My version of the button. // START - New ToDo button VStack { Spacer() // Push content to the right // New ToDo button Button(action: { showCreate.toggle() }) { HStack { Image(systemName: "plus.circle.fill") .foregroundColor(.blue) // Icon color Text("New ToDo") .foregroundColor(.blue) // Text color } .padding(.vertical, 10) .padding(.horizontal) .background(Color.white) // Button's background color .cornerRadius(20) // Pill shape .shadow(color: .gray, radius: 2, x: 0, y: 2) // Shadow for depth } .padding(.trailing, 180) // To match the floating button's right padding .padding(.bottom, 20) // To match the floating button's bottom padding }
@akbar.n
@akbar.n Жыл бұрын
Hello Brother, I have one Question ❓ I want to provide an icon & color at the time of creating todo. For that i had created antother view which had all SFsymbols, which is presented in sheet from where I can select the icon & that icon should be selected on the create todo view. But i m not able to do that. I way I was able to achive that result was buy create a model for Icon, same as you did for category. But that will use extra resources on the app, because I had created the relationship for Icon with TODO. Not is not approprate. Because we have all icon in sheet & from that sheet we just want that which icon was selected & should add that icon name String into todo. We cant append icon into todo because we have not still created new todo. Home View → Create Todo View → Icon Sheet → Create Todo View If I have 10 to 20 icon I can make array in the Create Todo View & that will work. I can do that. But I cant pass selected icon from Icon Sheet to Create Todo View. Can you make a Video 🎞 in which we can you can add icon & color on create category or create todo view. And categories should also not be on create todo view. If they are with the page we are able to select. But if we move it to another sheet we are not able to select it from there. So please also extract category selection from another sheet. In real apps user has lot of categories. Video Explaination : kzbin.info/www/bejne/goLIdYp7hstlaac Blog Link : noteplan.co/n/2D6DF362-6B45-4908-959C-106205FD4B99
@ChristopherDisdero
@ChristopherDisdero Жыл бұрын
Thanks for another great tutorial! Despite taking your advice and adding the code to set category.items = empty array and set title = empty string when adding a category, I'm still crashing when deleting a newly added category. The problem seems to be because we are trying to access the title property of a category item that may have already been removed due to the ForEach loop? Any ideas?
@tundsdev
@tundsdev Жыл бұрын
Thanks & Hmmm I wasn’t getting this behaviour anymore with crashes after testing this out a few times. Like I said at the start with my warning it could be an Xcode Beta issue. I’d open up a feedback and post on the developer forums 👌🏾
@jayelevy
@jayelevy Жыл бұрын
Yet another great set of videos! Thank you for what you do. I am getting an error “Type ‘Schema.Relationship.Option’ has no member ‘nullify’” in the Item model definition on the @Relationship line (code copied directly from your git). I’m wondering if this is a beta bug? Though, I’ve searched and see no reference to this. I’m stuck.
@tundsdev
@tundsdev Жыл бұрын
Hey man thanks, glad you enjoyed it. Also as well I added a pinned comment with this fix also you can check out that pinned comment and the thread with any updates you’ll need to change 👌🏾
@jayelevy
@jayelevy Жыл бұрын
Ah, thanks mate! My apologies… I didn’t see that embedded within the top pinned item.
@tundsdev
@tundsdev Жыл бұрын
No worries tbh i will update the pinned tweet so its clearer
@cloftis130
@cloftis130 Жыл бұрын
Great video Tunds. I think the crash you are experiencing may be tied to the new autosave feature implemented with SwiftData. I can consistently get my code to crash by deleting after an insert. To solve this, after the code to perform an insert: .insert(task) or .insert(category) Place an explicit call to the modelContext to save inside a do...catch: do { try modelContext.save() } catch { fatalError("Fatal error saving in function/class \(error), \(error.localizedDescription)") } I know it's not ideal, but I can't get the app to crash anymore. Maybe Apple will fix this in future betas.
@tundsdev
@tundsdev Жыл бұрын
This was the confirmed workaround by Apple in Xcode 15 Beta 2. Once it's been resolved there will be no need to do this anymore
@Ride8715
@Ride8715 Жыл бұрын
Do you mind explaining the property wrappers? All of these new ones are throwing me for a loop? @Bindable vs @Query is the thing that is catching me off guard. So you create the model on the class with @Model but you link it with @Query? If you want to change something is that when @Bindable comes into play? Yes that helps! Thank you. Also real credit to you to respond to comments so quickly.
@tundsdev
@tundsdev Жыл бұрын
Hey man sure @Query = This is a macro that allows us to execute queries to fetch data from SwiftData. Its part of SwiftData. @Bindable = This is part of the new Observation framework & allows us to listen to changes and make changes to classes marked with the new Observable macro you don’t want to use this unless you want to create some kind of state. By default the Model macro (i’ll get onto in a sec) uses this to allow you to update your SwiftData storage and listen to changes/make your UI react. @Model = This is part of SwiftData, it allows you to mark your models/schema that you’ll be working with and saving/fetching. So you mark your class with this macro to let SwiftData know this is your schema and your container to know this is what you’ll be working with Hope this helps
@abhishekthapliyal7933
@abhishekthapliyal7933 Жыл бұрын
This was really helpful, I was about to bang my head into a wall after the worst relationships examples given in WWDC23. Thanks a ton
@tundsdev
@tundsdev Жыл бұрын
I walked, so you can run. Glad you enjoyed the video and check out the whole series in the description box 👌🏾
@abhishekthapliyal7933
@abhishekthapliyal7933 Жыл бұрын
sure 🤩
@DavidM979
@DavidM979 Жыл бұрын
Github repo is missing from description
@tundsdev
@tundsdev Жыл бұрын
It’s not missing its the link is there to all my 2023 content
@tundsdev
@tundsdev Жыл бұрын
First person to spot the mistake in the intro wins nothing
@andresmade2853
@andresmade2853 Жыл бұрын
Upload the start up file lol
@tundsdev
@tundsdev Жыл бұрын
That’s not the mistake, but those files should be in the repo now 👌🏾
@30guarino
@30guarino Жыл бұрын
You didn’t make an array of .modelContent[Items.self, Category.self] in the @main App view …
@cagrgider8320
@cagrgider8320 Жыл бұрын
You are saying "Swift Data" but it writes "Core Data" on the top right. Did I win nothing? :))
@tundsdev
@tundsdev Жыл бұрын
You won nothing, yes
@lfan_tv
@lfan_tv 6 ай бұрын
Nice video! and can I know the .onAppear{} and .onAppear(perform: {}) is exactly same?
@tundsdev
@tundsdev 6 ай бұрын
Yes, it is
@teakodo
@teakodo 8 ай бұрын
Update the relationship by adding deleteRule: @Relationship(deleteRule: .nullify, inverse: \Category.items)
@tundsdev
@tundsdev 8 ай бұрын
I explain this in the pinned comment, there were updates in the beta you can see all the updates in the pinned comment and replies
@teakodo
@teakodo 8 ай бұрын
@@tundsdev thank you!
@evamartina9883
@evamartina9883 6 ай бұрын
@@tundsdev hi sorry, i can't see the comment, looks you have changed the pin
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 22 МЛН
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
1. SwiftData CRUD Operations
42:40
Stewart Lynch
Рет қаралды 31 М.
SwiftData Basics in 15 minutes
15:18
CodeWithChris
Рет қаралды 51 М.
SwiftUI Data Flow in iOS 17 - Observation & @Observable
7:57
Sean Allen
Рет қаралды 56 М.
Introduction to SwiftCharts: Creating Charts and Graphs in SwiftUI
48:20
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 22 МЛН