SwiftUI Photo Picker - Compressed Images, UIViewControllerRepresentable

  Рет қаралды 16,821

Sean Allen

Sean Allen

Күн бұрын

Head to squarespace.com/seanallen to save 10% off your first purchase of a website or domain using code SEANALLEN.
In today's video I show you how to allow your user to select a photo from their camera roll in SwiftUI. To do this, we integrate with UIKit and the UIImagePickerController using UIViewControllerRepresentable in SwiftUI. We use the common example of creating an avatar on a basic profile screen so we will also compress the image to not have a large amount of data.
If you like my teaching or presentation style, I've started creating my own courses:
seanallen.teachable.com/
Twitter:
/ seanallen_dev
Link to my book - How I Became an iOS Developer:
gumroad.com/l/sean-allen-origin
Timestamps:
0:00 - What You'll Learn
0:45 - Why UIImage in SwiftUI?
1:12 - Profile Screen Example
1:46 - How We Implement: UIViewControllerRepresentable
2:35 - TapGesture & Sheet Code
3:25 - Create the UIViewControllerRepresentable
6:44 - Create the Coordinator
8:28 - Passing the Selected Image to SwiftUI
13:28 - Run App & Fix Common Mistakes
16:11 - You Have the Image
16:38 - Compressing the Image
Hired.com:
hired.com/x/1n01g
Check out my podcast, iOS Dev Discussions:
itunes.apple.com/us/podcast/i...
Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):
Paul Hudson's Hacking With Swift:
gumroad.com/a/762098803
Donny Wals - Combine:
gumroad.com/a/909014131
Mark Moeyken’s SwiftUI Books:
www.bigmountainstudio.com/swiftui-views-book/fzc51
Objc.io Books (Thinking in SwiftUI & Advanced Swift):
gumroad.com/a/656585843
Ray Wenderlich Books:
store.raywenderlich.com/a/208...
Links to my iOS Dev Setup & iOS Dev Book Recommendations
www.amazon.com/shop/seanallen
#swift #softwaredeveloper #iosdeveloper

Пікірлер: 46
@seanallen
@seanallen 3 жыл бұрын
If you like my teaching/presentation style, I have my own iOS developer courses at seanallen.teachable.com. You can watch the first ~10% of each course as a free preview to get a feel for them.
@pedrohgmuniz
@pedrohgmuniz Жыл бұрын
Sean Allen is the best Swift programming teacher on KZfaq 🤩
@seanallen
@seanallen Жыл бұрын
Thanks for the kind words :)
@mark-theeverydayimagineer6163
@mark-theeverydayimagineer6163 2 жыл бұрын
This is one of exceptional videos. Over the last couple of years I've seen a couple of these Representable Coordinator type stuff. But as always, this gives enough logical background that's to-the-point enough to bring the concept across clearly. Suppose one could do some sort of data-size check to dynamically choose a compression value, so that you don't accidentally compress a file that may already be small in the library.
@jamesselvakumar6282
@jamesselvakumar6282 2 жыл бұрын
Very clear explanation of the concepts involved. Thank you very much Sean for this video.
@kdtechniquesofficial6153
@kdtechniquesofficial6153 3 жыл бұрын
I want this for my Final Year project.. Nice. Thanks, Sean bro.
@jaylensmith6308
@jaylensmith6308 Жыл бұрын
Coming back to this video 2 years later. My first iOS Developer tutorial I ever watched! I'm now confident in CreateML, async/await, MVVM, MVC, UIKit, MapKit, VisionKit, CoreData, remote notifications, and much more. Yet I still struggle with UIImagePickerController lol
@Connor-pj2tg
@Connor-pj2tg 3 жыл бұрын
Thanks Sean. Really appreciate this video and helped me out with my app :)
@seanallen
@seanallen 3 жыл бұрын
Happy to help, Connor!
@AnkitRathi7
@AnkitRathi7 3 жыл бұрын
Great video. All the issues in between like not setting delegate or dismiss is actually good way of teaching I think, that's what everyone, at least I do while actually coding in real project. Also getting protocol stubs from xcode for free is also what I do 😃
@sajademad117
@sajademad117 Жыл бұрын
man you're a life saver!
@echocase9528
@echocase9528 3 жыл бұрын
Great videos and great pronunciation! Thanks!
@seanallen
@seanallen 3 жыл бұрын
Glad you like them!
@megustaeljamonelchorizoylo560
@megustaeljamonelchorizoylo560 2 жыл бұрын
Great video as always! Different stuff and more painful is take a picture and rotate the device! Try it! Greetings
@rongnev3078
@rongnev3078 3 жыл бұрын
Thank Allen!
@ekkogaming5461
@ekkogaming5461 2 жыл бұрын
bruhhh your not allowed to be this good!! Cant believe I finally understood those stuff lol.
@freeythm2914
@freeythm2914 2 жыл бұрын
Thank You!
@EthanTremblayy
@EthanTremblayy 3 жыл бұрын
Hey, nice tutorial! By the way do you know any articles/videos that cover photo picker usage in case of limited access to the library. Thanks!
@lowell_
@lowell_ 3 жыл бұрын
Thanks for explaining the Coordinator class, haven't used it too much but seems less confusing now. I think I'll be using the new iOS 14 Photos picker however since I need multi-selection. I don't think the code will be too far off from this though.
@seanallen
@seanallen 3 жыл бұрын
I haven't taken a deep look at the PHPickerController, but I imagine it's very similar code.
@A_I_GHOST
@A_I_GHOST 2 жыл бұрын
Will this create a retain cycle? Because you have the ImagePicker references the Coordinator and the Coordinator also has a reference to the ImagePicker. Thanks
@xhidnoda
@xhidnoda 3 жыл бұрын
Hey Sean...i love your videos...can make a request for the next video? Can show how to make own pod with SwiftUI? Tks!
@janmensik9150
@janmensik9150 2 жыл бұрын
great, do you have any tip how to make after click button decide if take photo from camera or galery ?
@Engjeanluiz
@Engjeanluiz 3 жыл бұрын
Congrats!!!
@t.s3976
@t.s3976 2 жыл бұрын
Thanks for the great Video! I wonder if it's also possible to have some kind of Video Picker, where the user can select a video from their library and it's then used inside the App. Does anyone know?
@rahulchaurasia5011
@rahulchaurasia5011 3 ай бұрын
Excellent Video , Do We need also runtime permission For Photo Library and camera?
@mrparty333
@mrparty333 2 жыл бұрын
Hi Sean. With this method, could you save this image as Binary Data to a CoreData model? If so, what would that look like?
@gjermundification
@gjermundification 8 ай бұрын
kzfaq.info/get/bejne/hZ58ZMtip8-zaA.html
@FabricioMTL
@FabricioMTL Жыл бұрын
Ney Sean i have an error in line 16 and try with different persons and this the same thing every time line 16 have an error and don’t know why
@kenturnbull9679
@kenturnbull9679 3 жыл бұрын
I have a need to select pictures taken by the user's phone and save them into a list view in the app (basically a list of items including text and images). Would you use this method or the PHPicker Controller in iOS 14?
@seanallen
@seanallen 3 жыл бұрын
If you need multiple image selection I would swap out the UIImagePickerController with the PHPickerController.
@ykgreene
@ykgreene 3 жыл бұрын
Sean great tutorial! However, I would like to know if there is a way for me to do this using a set of images from inside my app versus from my camera roll. Like creating a collectionView of images and then using one of them instead of my camera roll. FYI really like your teaching style. Do you have any discounts for your teachable courses, I want to throw some funds your way but your course is just a little out of my budget currently. But I like your work and I respect the fact that you stepped out on your own. So I will support you the best I can, just keep the quality content coming.
@seanallen
@seanallen 3 жыл бұрын
Happy to hear you are enjoying the content, Yashim! If you wanted to use images from inside your app, I'm pretty sure you'd have to create your own custom view to show and implement all the selection stuff yourself. That's not something I'd have to research but hopefully that's a start in the right direction. I'd be happy to offer you a discount since you'd like to support. Email me at seanallen dot dev at gmail.com and we'll work something out.
@raymundoortiz7269
@raymundoortiz7269 2 жыл бұрын
Do you know how to pickup a Video from the gallery??
@jaylensmith6308
@jaylensmith6308 2 жыл бұрын
Good tutorial, but my image is not updating within the first view. It’s still stuck to the original State ui image
@billbyrnes422
@billbyrnes422 2 жыл бұрын
Does anyone know how to save the photo using CoreData after publishing the photo?
@rickywitherspoon2861
@rickywitherspoon2861 3 жыл бұрын
I’m surprised you’re not doing this demonstration with PHPickerController. Any reason why?
@seanallen
@seanallen 3 жыл бұрын
I forgot it existed, to be honest.
@SBSanook
@SBSanook 3 жыл бұрын
PHPickerController allows multiple selections (which UIImagePickerController can't do), so you can't edit the selected photo like UIImagePickerController. Since only one photo will be selected for a profile image, it seems that editing ability is a good tradeoff.
@omarvideos2274
@omarvideos2274 3 жыл бұрын
Hi but how can i cache them
@faridmontieli6795
@faridmontieli6795 3 жыл бұрын
Excellent tutorial! Is it normal that every time we select an image, it is automatically stored in the device?
@seanallen
@seanallen 3 жыл бұрын
In the example in the video, yes, you have access to whatever image they select via the delegate method we discuss. It's not stored on the device forever, it's in memory. It's up to you to do what you need to do with that image (send it to a server for example).
@faridmontieli6795
@faridmontieli6795 3 жыл бұрын
@@seanallen Okay, thanks for answering my question. Greetings from Argentina!
@berni303
@berni303 3 ай бұрын
11:30 I think it's a mistake to make a copy of the parents' view here. By copying the structure, you may unintentionally suggest that you can modify other non-binding properties of the view, but you cannot as it's not a reference to the original view.
@ruptapas
@ruptapas 3 жыл бұрын
Thanks, Sean, great tutorial... I learnt many important aspects of communicating between SwiftUI & UIKit using the coordinator. One thing that I am still struggling with is if I have a UIKit app that is using Storyboard and now I want to update my first view controller with SwiftUI how do I do that arrangement in AppDelegate? Any pointers on this will be of great help. Take care and more power to you...
@seanallen
@seanallen 3 жыл бұрын
I believe you want to look into tutorials or content about UIHostingController and SwiftUI. I don't have any personally, but they are out there. That's how you implement SwiftUI into an existing UIKit app.
SwiftUI Custom Path Drawing - Map Balloon Shape
15:02
Sean Allen
Рет қаралды 8 М.
NavigationStack - SwiftUI Programmatic Navigation - iOS 16
20:20
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН
Inside Out 2: Who is the strongest? Joy vs Envy vs Anger #shorts #animation
00:22
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 207 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 38 МЛН
New SwiftUI Photo Picker - Single & Multiple Selection
12:42
Sean Allen
Рет қаралды 10 М.
Your App Will Get Rejected | New Privacy Rules - 2024
11:26
Sean Allen
Рет қаралды 35 М.
How to use PhotosPicker in SwiftUI & PhotosUI | Swift Concurrency #17
17:41
Why Agent Frameworks Will Fail (and what to use instead)
19:21
Dave Ebbelaar
Рет қаралды 35 М.
CloudKit - Intro, Pricing, Terms, & Definitions
17:26
Sean Allen
Рет қаралды 22 М.
KMP vs. Flutter - Who Will Win The Cross-Platform Battle?
16:19
Philipp Lackner
Рет қаралды 39 М.
How to use SDWebImage in SwiftUI | Swift Packages #1
25:39
Swiftful Thinking
Рет қаралды 4 М.
SwiftUI: UIImagePickerController with UIViewControllerRepresentable
21:14
Lets Build That App
Рет қаралды 18 М.
📱магазин техники в 2014 vs 2024
0:41
djetics
Рет қаралды 653 М.
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 65 МЛН
Это - iPhone 16!
16:29
Rozetked
Рет қаралды 409 М.