How To Store An Image In SwiftData 📸 | SwiftData Tutorial | #8

  Рет қаралды 8,495

tundsdev

tundsdev

Күн бұрын

⏭️ Next Video: Prefill Relationships in SwiftData - • How To Preload Relatio...
⏮️ Previous Video: Save API Data In SwiftData - • Discover How To Save Y...
See How To Store An Image In SwiftData 📸 | SwiftData Tutorial
**********************************
Timestamps:
00:00 - Intro
00:33 - How To Use SwiftUI PhotoPicker
09:38 - Setting Up Our SwiftData Model To Save Data
13:58 - Displaying An Image Saved In SwiftData
15:03 - Updating Our Image In SwiftData
17:41 - Adding an Image Viewer to our ToDo screen
21:53 - How To Save Image To External Storage SwiftData
**********************************
In this SwiftData tutorial, we'll be looking at how to store an image in SwiftData. We'll be using the SwiftUI PhotosPicker to see how to store data in SwiftData.
We'll also look at how to read this data and display an image on the screen, we'll then discover how to update data in SwiftData. As well as improve the UI/UX of our app by using a third-party library called SwiftImageViewer which you can check out below.
github.com/fuzzzlove/swiftui-...
We'll then look at using the external storage option in the @Attribute macro.
**********************************
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
tunds.dev/#courses
**********************************
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
www.youtube.com/@tundsdev/join
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 KZfaq channel
kzfaq.info?su...
**********************************
Download Source Code
Interested in looking at the source code? Then check out the GitHub Repo below
github.com/tunds/youtube-cont...
**********************************
EditorKeys
View Editor Keys Amazing Products with the link below and use the discount code for 10% off any product
www.editorskeys.com/tundsdev
Get a 10% Discount Code on any product with the code below
TUNDSDEV
See my keyboard cover in action with my review below 👇🏾
• Increase Your Xcode Pr...
**********************************
RØDE Wireless Mic
amzn.to/3D5qo3V
RØDE SmartLavPlus Microphone
amzn.to/3DtVUdG
2021 Apple MacBook Pro (16-inch, Apple M1 Pro chip with 10‑core CPU and 16‑core GPU, 16GB RAM, 1TB SSD) - Space Grey
amzn.to/3Drc2fH
Apple Magic Keyboard with Numeric Keypad (Wireless, Rechargeable)
amzn.to/3VUctXh
Apple Magic Mouse
amzn.to/3sqXSoM
Secretlab TITAN 2020 Charcoal Blue Gaming Chair
amzn.to/3D2jVXI
ErgoFoam Ergonomic Foot Rest for Under Desk
amzn.to/3srJOLM
Lumbar Support Pillow
amzn.to/3eXVfrg
Macbook Stand for Apple Macbook and All Notebooks
amzn.to/3DqG7vR
Portable Chair Green Screen Background
amzn.to/3gG62GU
**********************************
#iosdev #iosdevelopment #swift #swiftlanguage #xcode #appdevelopment #mobileappdevelopment #iosappdevelopment #appdeveloper #iosprogramming #iosengineer #appdevelopmenttips #iosdevelopmenttips #swiftui

Пікірлер: 78
@tundsdev
@tundsdev 11 ай бұрын
🚨Bug Fix🚨 There seems to be an issue with the way the clipping images is handled in SwiftUI it can cause elements to overflow and block the touch targets of other element in this case the todo button. In order to fix this you'll need to set the z index on the image to -1, below is an example of this Replace Image with the following below Image(uiImage: uiImage) .resizable() .aspectRatio(contentMode: .fill) .frame(height: 120) .clipShape( RoundedRectangle(cornerRadius: 10, style: .continuous) ) .zIndex(-1)
@tundsdev
@tundsdev 8 ай бұрын
There seems to also be a bug where if you have multiple images on the screen you can only view the last one. Which seems to be a bug with the lib that I used oooppsss lol. I'll try to post a gist with a link to some update I made to resolve this issue.
@holycrosscv
@holycrosscv 6 ай бұрын
I removed the lib, and it still selects just the last image. @@tundsdev
@nileshjdarji
@nileshjdarji 18 күн бұрын
Wow Tunds. I like what you showed for the external storage. Very nice. I am really enjoying this series.
@CarlosRomanAlcaide
@CarlosRomanAlcaide 2 ай бұрын
This video is one of the best explanations I’ve found about how to store images in SwiftUI!
@tundsdev
@tundsdev 2 ай бұрын
Glad it was helpful!
@gccount
@gccount 4 ай бұрын
finally , this video helped me. the key part is converting image data to UIImage , then to Image
@tundsdev
@tundsdev 4 ай бұрын
Glad it helped!
@penyt
@penyt 11 ай бұрын
Looking forward to CloudKit with SwiftData! Thanks for another super useful tutorial :)
@tundsdev
@tundsdev 11 ай бұрын
Glad you enjoyed it 👌🏾
@misaellanderosichante3293
@misaellanderosichante3293 2 ай бұрын
Good tutorial bro help me a lot
@ben.aka.bigben
@ben.aka.bigben 8 ай бұрын
Well done, thank you for this valuable tutorial
@macmcmillen6282
@macmcmillen6282 11 ай бұрын
Excellent series of videos. You explain things very well, so thanks for sharing this!
@tundsdev
@tundsdev 11 ай бұрын
Thanks, glad you enjoyed it 🤝
@thomasfahlke4253
@thomasfahlke4253 11 ай бұрын
Hi tunds, great work and yes, I learned a lot. Just right for the next project. Thank you
@tundsdev
@tundsdev 11 ай бұрын
That’s great to hear 👌🏾
@ConnorH713
@ConnorH713 11 ай бұрын
Great video, before this I was trying to cherry pick from older Core Data tutorials to achieve this functionality for my app. Thanks for posting!
@tundsdev
@tundsdev 11 ай бұрын
Glad it helped!
@sxmiotb2834
@sxmiotb2834 10 ай бұрын
this was a big help. thank you so much
@tundsdev
@tundsdev 10 ай бұрын
Great to hear 👌🏾
@profgallaugher
@profgallaugher 6 ай бұрын
Your work is great. Keep at it!
@tundsdev
@tundsdev 6 ай бұрын
Thanks a lot!
@HaukeCode-ye8fe
@HaukeCode-ye8fe 11 ай бұрын
Really loving these videos on SwiftData Tunds! Would love to see a lesson on how to integrate CloudKit with SwiftData so different users can access related data. Specifically would be cool to see an example where you use some shared cloud data as well as some local data and keep things straight. Thank you!
@tundsdev
@tundsdev 11 ай бұрын
Thanks, glad you’re enjoying it. I do have some cloudkit content planned soon, for both this & another paid course i’m workin on. Also do you mean users can share todo’s? And like collaborate on them together?
@HaukeCode-ye8fe
@HaukeCode-ye8fe 11 ай бұрын
@@tundsdev yes! A shared todo app where you can assign one another is a great example. Mostly wanting to learn how to think about managing local private data through SwiftData and then local shared data with SwiftData and iCloud and how to manage between them. For instance, what if I created a private todo and then later wanted to add someone else to it. Hope that makes sense, thanks! One other thing I am interested in, but may be to far off topic is also how you might manage local SwiftData and Firebase integration for cloud sharing.
@keatsp
@keatsp 9 ай бұрын
Amazing job. Very easy to follow your tutorials. I would love to see how to get an image from the camera.
@tundsdev
@tundsdev 9 ай бұрын
Thanks & SwiftUI doesn’t support choosing the camera as an option just yet you still have to use UIKit mixed in with SwiftUI 👌🏾
@anirudhcodes
@anirudhcodes 11 ай бұрын
Awesome
@tundsdev
@tundsdev 11 ай бұрын
Glad you enjoyed it 👌🏾
@lickmyshoe182
@lickmyshoe182 10 ай бұрын
From one Brit to another - Thank you ever so much for these tutorials, the way you explain things is great and I genuinely understand the concepts once you’ve gone through them. Keep up the good work!
@tundsdev
@tundsdev 10 ай бұрын
This is great to hear, glad you enjoy the content 🙏🏾
@meet071
@meet071 11 ай бұрын
Hello. Can you please share how we can store multiple images as a form of array in swiftData. Thanks :)
@tundsdev
@tundsdev 11 ай бұрын
Sure I can add it to my list 👌🏾
@gerardgomez5987
@gerardgomez5987 10 ай бұрын
Also interested in this.
@kkpvb
@kkpvb 11 ай бұрын
Good Tutorial, I’m learning SwiftUI from Thailand. 🙌🏻
@tundsdev
@tundsdev 11 ай бұрын
Awesome i recently went bangkok it was really nice, especially your mcdonalds 💕
@kkpvb
@kkpvb 11 ай бұрын
Really?, I guess if you've been here recently Show that you like McDonald's decorated as Newjeans for sure hahaha
@rudiprestianni7822
@rudiprestianni7822 11 ай бұрын
really like your tutorials. Would you do a tutorial on how to handle dictionaries with SwiftData?
@tundsdev
@tundsdev 11 ай бұрын
I have an upcoming vid that will show you how to handle custom data types SwiftData doesn’t support, another alternative is to use json & save it as a string amd convert it back to an object
@macmcmillen6282
@macmcmillen6282 11 ай бұрын
Have you tried saving multiple images per todo? I'm guessing that would require an array of the Data type. I see that Beta 8 has been released. Looks like a lot of SwiftData fixes.
@PeteLorimer
@PeteLorimer 11 ай бұрын
Great video. I followed along and got images into my app in no time. Question: When using the @Attribute(.externalStorage) where exactly does the image get stored? And if I were to integrate CloudKit for syncing the data across all my devices, would the images get synced as well?
@tundsdev
@tundsdev 11 ай бұрын
Thanks & similar to CoreData its stored in a hidden folder that is then referenced within SwiftData rather than the whole image being stored. I’ve not worked too much with CloudKit but it’s next up on my list to explore 👌🏾
@misaellanderosichante3293
@misaellanderosichante3293 2 ай бұрын
Would the image sync with CloudKit if we use external storage?
@pgong415
@pgong415 8 ай бұрын
First, your video is really helpful especially in terms of saving images in Data type rather than image one and storing the images in an external file. Second, there is a bug in my experiment - if pick one image for item 1, for example, and one image for item 2, item 3, so on, when you click on image for item 1 or item 2, always the image for item 3 (or last item) is presented. I do not know if this is the case for your app or something wrong for my experiment. Appreciate it in advance for your reply. Thank you for your efforts anyway.
@tundsdev
@tundsdev 8 ай бұрын
Hi, So this does store the image externally it’s actually better to do this rather than store the data directly in the database, there’s been a few updates to Xcode since I last released this so i’d have to investigate this issue for you 👌🏾
@tundsdev
@tundsdev 8 ай бұрын
Hey so I just had a quick look and it's linked to the library that I've used in the video...When I have some time i'll try to post a gist with an updated solution without the lib but it won't have zoom functionality etc.
@ian7666
@ian7666 11 ай бұрын
Be nice to see a comparison of SwiftData and Realm… I love Realm, should I even think of using SwiftData?
@tundsdev
@tundsdev 11 ай бұрын
Nice suggestion, i'll consider it!
@w0mblemania
@w0mblemania 11 ай бұрын
This was very useful, thanks! Question: by default, if we use the .externalStorage attribute, are the images being saved in a place automatically backed up by iCloud?
@tundsdev
@tundsdev 11 ай бұрын
Thanks & nope to get that functionality you’d to setup an icloud container, which I may have a video on very very soon 👀
@w0mblemania
@w0mblemania 11 ай бұрын
@@tundsdev Thanks!
@kenturnbull9679
@kenturnbull9679 11 ай бұрын
I like this and can use it. I am working on an inspection app that requires more than one photo for an item. How about making your image into a carousel or horizontal scrollview to allow more than one image? As for Butties...do you still have Jam butties?
@tundsdev
@tundsdev 11 ай бұрын
I love jam butties 🔥🔥🔥 i did consider it but the video would be way too long 😬
@kenturnbull9679
@kenturnbull9679 11 ай бұрын
>@@tundsdev My friend from Manchester also used the expression ..."Manky" and called me Neddy; and I'm Canadian. How about another video on using the package to generate a collection of photos for an item? Love to see it extended.
@TB84060
@TB84060 9 ай бұрын
Yes, please help with this. I am in the exact same quandary. I want to show a horizontal scrollview of images for each item.
@nguyenan8327
@nguyenan8327 7 ай бұрын
Hi Tunds, thanks for your tutorial. However, i read in multiple places that we should not store image data directly in database field, should we do that for SwiftData as well, what's your ideas on this?
@tundsdev
@tundsdev 7 ай бұрын
👋🏾 so technically this isnt stored in the database its stored in an external reference to a folder on the device to prevent large data being saved in the data model
@nguyenan8327
@nguyenan8327 7 ай бұрын
oh thanks for your explanation if can pls help to guide on how to store multiple images in a record, thank you very much! I try the array but it keeps having some issues 😅
@WilfClegg
@WilfClegg 8 ай бұрын
Hi Tunds! Once again, many thanks for this tutorial. It rocks, as usual. I noticed a small bug (maybe it is on my install only?) When I add two or more items to the ToDo list (and each with a photo), The SwiftUIImageViewer doesn't always present the image that I tap on. Can you check on this to see if works ok on your install? Thanks....Wilf
@tundsdev
@tundsdev 8 ай бұрын
Hey so I just had a quick look and it's linked to the library that I've used in the video...When I have some time i'll try to post a gist with an updated solution without the lib but it won't have zoom functionality etc.
@WilfClegg
@WilfClegg 8 ай бұрын
@@tundsdev Thanks Tunds, I’m glad you confirmed the issue. Alternatively, I can create a .sheet, then apply .infinity framing, pinch and magnification, etc. This would avoid the need for an add-on package?
@tundsdev
@tundsdev 8 ай бұрын
@WilfClegg Yep that should work too 👌🏾
@huynhvandutran8014
@huynhvandutran8014 8 ай бұрын
Do you know where the actual data (imageData in your example) is stored when we use externalStorage? Like is it in the Document folder? I don't see the image data in there.
@tundsdev
@tundsdev 8 ай бұрын
👋🏾 You have to open up the path to the data model file and in that folder there is folder called external storage that holds all of the external files
@user-wn8sr2wr1c
@user-wn8sr2wr1c 11 ай бұрын
I'd like to learn how to handle images in Coredata, is there a video on that?
@tundsdev
@tundsdev 11 ай бұрын
Nope, not yet. Maybe i’ll add it to my shortlist 👌🏾
@user-wn8sr2wr1c
@user-wn8sr2wr1c 11 ай бұрын
@@tundsdev Thank you. I'm trying to store the image as a binary data type with Core Data, but most of them recommended storing only the PATH and managing it locally. If I store only PATH in coredata as recommended, won't the local images be deleted if the user deletes the app when using cloudkit? Then when I reinstall the app, I won't be able to retrieve the images even if PATH exists in coredata. I'm still looking for a way to store and manage them correctly in coredata (considering that there will be many images). I'd be grateful if you could post a video about it in the future. 🙏
@johnpill1
@johnpill1 5 ай бұрын
Came here for the tutorial... left to get a bacon butty 😂
@tundsdev
@tundsdev 5 ай бұрын
Brown, Ketchup or Both sauces? Which one are you? 👀
@johnpill1
@johnpill1 5 ай бұрын
@@tundsdev Bacon bap = BBQ. Sausage bap = Ketchup. Fry up = Brown. There are rules :D
@johnpill1
@johnpill1 5 ай бұрын
On a less serious note, I was trying to get a slider working in SwiftData in the Bindable view and I keep getting an error on the container form. Works fine in the original sheet. Is this a SwiftData issue or something I am missing?
@tundsdev
@tundsdev 5 ай бұрын
I’d need more context to try to help out unfortunately, this sounds very specific to your project
@benjiloya_ios_dev
@benjiloya_ios_dev 8 ай бұрын
how to add Video in swiftData???
@holycrosscv
@holycrosscv 11 ай бұрын
Loving this series. Thanks! Did you find that @Relationship(.nullify, inverse: \Category.taskCat) throws an error with beta 6 "Type 'PropertyOptions' has no member 'nullify'" Thanks. Blessings, --Mark
@holycrosscv
@holycrosscv 11 ай бұрын
Ah, beta 6 added deleteRule: .nullify
@tundsdev
@tundsdev 11 ай бұрын
Haha yep, no worries glad you enjoyed the vid 👌🏾
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,8 МЛН
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 13 М.
CloudKit - Intro, Pricing, Terms, & Definitions
17:26
Sean Allen
Рет қаралды 22 М.
9. SwiftData Storing Images and Bug Fixes
23:15
Stewart Lynch
Рет қаралды 3,7 М.
Play: The Secret Weapon for iOS Devs & Designers
10:12
Sean Allen
Рет қаралды 25 М.
Swift Data Relationships 🚀 | SwiftData Tutorial | #2
26:52
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН