Support us

Connect

Creating, editing, and deleting model objects – SwiftData Starter Project 4/8 – YouTube Dictation Transcript & Vocabulary

Welcome to FluentDictation, your best YouTube dictation website for English practice. Master this B1 level video with our interactive transcript and shadowing practice tools. We've broken down "Creating, editing, and deleting model objects – SwiftData Starter Project 4/8" into bite-sized segments, perfect for dictation exercises and pronunciation improvement. Read along with our annotated transcript, learn essential vocabulary, and enhance your listening skills. 👉 Start dictation practice

Join thousands of learners using our YouTube dictation tool to improve their English listening and writing skills.

📺 Click to play this educational video. Best viewed with captions enabled for dictation practice.

Interactive Transcript & Highlights for Dictation

1.[Music] after you've defined your data model you've used act query to read it back out again and use that resulting array in some kind of Swift UI layout now comes the fun part building some new UI so users can create delete and edit their own destinations rather than relying on samples again and again and again now the easiest of these is deleting data so we're going to start there you can delete any data from Swifty y by calling the delete method on a Model context passing in that object now on our Swift UI view right now we're using a regular for each Loop here to iterate over all destinations passed in from our query we can now write a very similar kind of deleting code you'd use in any kind of Swifty y thing so you'd have an on delete per modifier to get swipe to delete working out of the box and so down below add sample out a new method here called delete Funk even uh delete destinations accepts an index set just like regular 5 y code it then Loops over the index like this in index set reads the value out from the array at the index and here's a new part we got to call delete on our model context passing in that object delete this thing here we'll say model context

2.delete that destination that's how you delete items in Swift data and now we can attach a modifier to our for reach to call that to get swipe to delete so I'll save for our for here we'll do on delete perform and I want to fill in the function version there we go perform no it's going to fill out for me every time cool perform uh delete destination there we go got there in the end boom it works I can press command R give it a try we have our previous sample ler there I can just swipe and choose delete or just swipe the whole way across like that the next easiest task is editing data which means making a new Swift UI view with some various options in place want to make sure we have text Fields so user can change a uh destination's name and details properties a date picker so you can choose date and time that arrive there plus another picker to handle priority of destination how much do you want to go to this place if you put all those things into a regular Swift UI form we'll get a great layout out of the box so press command n make a new Swift UI View Press next and call this one edit destination view like that now this needs to know the destination that's been chosen which one we're trying to edit right now and if we just wanted to read values to show things on the screen we would say VAR destination is a destination like that but here just reading values is not enough because we want to bind them to text fields and Pickers and similar so you can actually edit the values over time instead of having a plain property like this we're going to add an extra property wrapper here called at bindable which is able to create any kind of bindings for any Swift data object this is actually built for the Swift observation system that's new for iOS 17 but because Swift data is built on top of observation it works just as well here too so this property is going to be at bindable V destination is destination and now we got a property here of course our previous struct won't build anymore worse we can't just make a temporary destination and throw it around in here cuz Swift data won't know where to create it where it's being stored there's no active model container there's no context around to make that thing in for our preview now to fix this we're going to make a custom model container by hand and we're going to do it in a very particular way because it's a preview we don't want to use live data we want temporary data so we're going to make an inmemory storage area so it means that we can create it in memory just for the previewing purposes make changes and they're all thrown away on the preview ends this takes just four steps first make a new type called a model configuration that will tell us we want inmemory storage for our data second we'll use that configuration to make a custom model container for our destination model third make an example destination object with some sample data so and it looks realistically good on the screen uh this will automatically be made inside the container we've made so it works and finally send that object into our destination view here along with the model container so it'll all work nicely together now we haven't done steps one and two before because they weren't required they were done by that magical model container four thing here we do need them now so we can create by hand and customize it so in our preview here we're going to say as a do block with our code in we'll say make a configuration equal to model configuration you can see here is stored in memory only that will be true do not store this to disc in the long term then we'll say let container be try model container for our destination self with configurations of that configuration and now we can make our objects here we'll say our example is a destination with a name of example destination and details will be some long text simulate a good screen here so I'll say um example details go here and will automatically expand vertically as they are edited be UI will do anyway and now finally we can do return that destination view with destination being our example object and pass in the model container to like so container boom and then just catch any errors so I'll say catch uh fatal error fail to create model container like so now it's unhappy here it can't find these things I'll just do uh the the fix it to import of data boom it should be much happier now yes okay good so at this point our code compiles cleanly again but be very very careful if you had not done these two lines of code your preview would really really struggle obviously right now it's just you know hello world whatever there's not a lot going on here which is fine uh but uh in the real thing you want to make sure you have the configuration and container built ahead of time like that it will cause problems your preview just crash mine's failing to build the file right now let is having a little annoyance to itself little tantrum um but it should be fine your side compiles cleanly for sure that's what we care about so now we can start to fill in this view body here uh with those S edit our destination here this is regular Swift UI code nothing here it has no idea it's reading and writing to Swift data doesn't care just an object as far as it's concerned so we're going to say there's a form where the text field called name bound to text of dollar destination

3.name then a text field of details with text bound to destination details this is a multi-line field so I'll say it has an axis of vertical so it grows as a type we'll make a date picker called date with selection bound to destination date and then for priority we're going to use a picker low medium and high this needs a separate section here because uh segmented controls are unlabeled sadly in swiftui by default on iOS and so we're going to say section with the title of priority making it clear what this thing actually means then we'll do a picker uh called priority with selection bound to destination priority and the values will be 1 2 and three uh low medium and high we'll do slightly more interesting than low medium and high CU that's quite dull uh we're going to say uh me is tag one then we'll do maybe for tag two and text must for tag three do they want to go maybe me or must and I'll say pick a style here is segmented so there only one type of change options here I'll also add a navigation title to our form saying edit destination and then a navbar title display mode of inline detail view now and now we can go back to our content View and make navigation work for our list and this means placing a navigation link inside our for each so each row inside our list is navigation link moving to a destination we'll preview work to find out thinking about it no okay I'll leave it to cry by itself uh over in content view we'll make that change now we'll say here's our 4 each right now um inside there so right here this is where we're going to say there a navigation link with the value of our destination and push a whole v stack inside there we also want to add a navigation destination modifier below our nav title right here so to Y knows to move to that new editing view whenever a navigation is is triggered so we'll say here there is a navigation destination for destination

4.self and this thing has to take a destination and return a view of course that's exactly what our edit destination view does so I'll just do that do init that should now all work let's let's find out I'll press command R I'll delete uh Rome like that here and uh I've deleted it and I'll new ones boom I'll choose Naples excellent Naples is there go back and choose Florence very very nice and this is all live data by the way I can say you know let's not go to Florence let's go to Verona and now back here boom Ron is there straight away so we have editing working very very nicely at this point Swift has taken care of the rest for us so now we have editing working adding destinations is really easy because we'll just insert a new empty destination to our array and then make it edit edit immediately just show for editing now this been making a handful of small changes starting with some storage to track the path of our navigation stack so we can store in state here and adjust it saying now show this thing for editing so a new property here in content view we'll do at State private VAR path is an array of destination like that second we want to bind that thing to the path of our navigation stack so I'll say the path of this thing is dollar path third we want a new method and content view that creates a new destination add it to our model array this thing here destinations the context and then puts it into the nav path show it for editing right now so down here we're going to say let's do here Funk add destination step one make a new empty destination let destination equals destination like that step two we're not going to just force it into the array that's given to us by Swift data instead we do the same thing we did before we inserted the model context like this we do model context do insert destination and then we'll make our our path value here equal to destination like that so we're saying make that thing be shown in our navigation stack right now and finally we'd add another button here in our Toolbar to add new destinations we'll say button add destination system image of plus action of add destination and we're done press build and run again I'll press plus boom new one appears to away I'll say where I really want to go else let's do uh like Positano or a malfie I don't know uh somewhere wonderful not position you silly thing posit ah spelling oh I know Capri there you go it can't complain Capri yeah good uh and that'll appear here straight away so you can see it as it animates you can see it adds it boom down there and slide it in straight away so adding now works great too with that done you can now remove this add samples code it's not required anymore we're now dealing with real user data

💡 Tap the highlighted words to see definitions and examples

Key Vocabulary (CEFR B1)

commander

B1

One who exercises control and direction of a military or naval organization.

Example:

"Commander build and run again I'll press"

previously

B1

(with present-tense constructions) First; beforehand, in advance.

Example:

"previously so it works and finally send"

meaningfully

B2

In a meaningful or significant manner.

Example:

"meaningfully long text simulate a good"

otherwise

B1

Other than supposed; different.

Example:

"otherwise it will cause problems your"

surprising

B1

To cause (someone) to feel unusually alarmed or delighted by something unexpected.

Example:

"surprising here it has no idea it's"

something

B1

An object whose nature is yet to be defined.

Example:

"something slightly more interesting than"

correctly

B1

In a correct manner.

Example:

"init that should now all work correctly"

automatic

B1

A car with automatic transmission.

Example:

"the screen uh this will automatically be"

dynamically

B2

Of a dynamic nature; variable or constantly changing nature.

Example:

"state here and adjust it dynamically"

everywhere

B1

In or to all locations under discussion.

Example:

"say where I really want to go everywhere"

Want more YouTube dictation drills? Visit our practice hub.

Want to translate multiple languages at once? Visit our Want to translate multiple languages at once? Visit our Multiple Language Translator.

Grammar & Pronunciation Tips for Dictation Practice

1

Chunking

Notice how the speaker pauses after specific phrases to help comprehension.

2

Linking

Listen for connected speech patterns when words flow together.

3

Intonation

Pay attention to how pitch changes to emphasize important information.

Video Difficulty Analysis & Stats

Category
science-&-technology
CEFR Level
B1
Duration
880
Total Words
2164
Total Sentences
321
Average Sentence Length
7 words

Downloadable Dictation Resources & Materials

Download Study Materials

Download these resources to practice offline. The transcript helps with reading comprehension, SRT subtitles work with video players, and the vocabulary list is perfect for flashcard apps.

Ready to practice?

Start your dictation practice now with this video and improve your English listening skills.