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

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

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.

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*

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

*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
Рекомендации по теме
Комментарии
Автор

🚨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(
10,
style: .continuous)

)
.zIndex(-1) <--- Fix is here

tundsdev
Автор

finally, this video helped me. the key part is converting image data to UIImage, then to Image

gccount
Автор

This video is one of the best explanations I’ve found about how to store images in SwiftUI!

CarlosRomanAlcaide
Автор

Looking forward to CloudKit with SwiftData! Thanks for another super useful tutorial :)

penyt
Автор

Wow Tunds. I like what you showed for the external storage. Very nice. I am really enjoying this series.

nileshjdarji
Автор

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!

ConnorH
Автор

Many thanks. This helped me greatly. The official Apple Tutorial also works and it's very complete, but I was missing where the "essential" part was.

josemcgomes
Автор

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!

HaukeCode-yefe
Автор

Hi tunds, great work and yes, I learned a lot. Just right for the next project. Thank you

thomasfahlke
Автор

Good Tutorial, I’m learning SwiftUI from Thailand. 🙌🏻

kkpvb
Автор

Excellent series of videos. You explain things very well, so thanks for sharing this!

macmcmillen
Автор

this was a big help. thank you so much

sxmiotb
Автор

Well done, thank you for this valuable tutorial

ben.aka.bigben
Автор

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.

pgong
Автор

Amazing job. Very easy to follow your tutorials. I would love to see how to get an image from the camera.

keatsp
Автор

Hello. Can you please share how we can store multiple images as a form of array in swiftData. Thanks :)

meet
Автор

really like your tutorials. Would you do a tutorial on how to handle dictionaries with SwiftData?

rudiprestianni
Автор

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?

wmblemania
Автор

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?

nguyenan
Автор

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.

macmcmillen