Use UIViewRepresentable to convert UIKit views to SwiftUI | Advanced Learning #13
Вставка
- Опубліковано 22 сер 2024
- In this video, we will learn how to convert views from UIKit into SwiftUI. As I've mentioned before, I definitely recommend using native SwiftUI components whenever possible because they are stable and much easier to work with. However, not all SwiftUI components are highly customizable and there are occasional situations where we might want to convert something from UIKit and use it in our SwiftUI application. As you'll see, putting UIKit elements onto the screen in SwiftUI is actually pretty easy. The hard part, which we will also cover, is learning how to communicate the data flow from SwiftUI to UIKit and vice versa, from UIKit back to SwiftUI.
Next video: • Use UIViewControllerRe...
Last video: • Create a custom naviga...
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-t...
DISCORD: / discord
GITHUB: github.com/Swi...
SAY THANKS: www.buymeacoff...
UIKit works so flawlessly (I started on SwiftUI and use it when need be). I hope thats where SwiftUI grows to
SwiftUI adoption is on the rise don't worry 🥳
Hey man, I've been working with UIKit for the past 18 months and need to learn swiftUI for a new job ,and your videos are great for people that know swift but and new to swift ui. really clear and and very good examples, make me understand things that other teachers didn't explain very well. Keep it up!
I'm impressed. I'm too old for this stuff. I wish I were young. There was no OS when I was a teen.
Truly wonderful video. I’ve used viewrepresentables before but still learned something new. Great job Nick
Thanks a lot! Kind of scary at first but it all makes sense.
Now my understanding is much better than before. Maybe it helps me to solve my Custom Annotation problem. 😅
Thank you very much it's an amazing explanation.
thank you , i can easily understand in a short time
That was really excellent and just what I needed today!
What a gem!
this is so helpful thanks a ton!!
If youtube let me like this video 1000 times - I've did it )
Hi Nick and firstly thanks for all that work on your channel!! May it be, that the last marker at 24:03 in 10/06/2023 now is deprecated? It says to me "Value of type 'some View' has no member 'updatePlaceholder'".
All best ✌
Edit: no, it still works (I just messed up the modifier-hierachy)
Thank you
ohhhh after watching this video i came to fast conclusion.. I will never use swift UI in legacy project, so match setup and extra code )))
Thank you for the explanation nick! Does it also work with the UIKit view gesture, for example pinch zoom
Thanks 👍👍👍🙏👍🙏
Very nice Nick! I have a need for a grid entry within a ScrollView in SwiftUI. Is that something that I can do in this same manner? Seems that getting all of the data back into SwiftUI would be a challenge (for me LOL.) I tried building a grid using a LazyVGrid with gridColumn widths assigned and it works but when I tried to allow data entry directly into the grid using a TextField in SwiftUI it does not behave very well. I have dates, Doubles, & Currency to be entered and the rows / columns become too large on a phone-sized screen. I can fill the grid with data from the users DB but data entry is clunky.
Is this how you would approach a problem like this? If so, any hints? Thanks so much for your great tutorials! I have followed every video you have published. So well done!
Hey Brad! From the sounds of this, I don't think you would need UIViewRepresentable. I would probably use a LazyVGrid inside a ScrollView. There have been some bugs with the LazyVGrid so I'm not sure if what you're running into is a bug or maybe something is configured to update correctly (usually the case for me haha). If you really think it's a LazyVGrid bug, then you can make you're own grid using a VStack with HStacks inside?
is it worthing to write a 100 line for only a placeholder Color ! I would go with the regular swift ui one
Hi Nick, Love all your videos.
New to Swift, pretty comfortable with SwiftUI (thanks to you :) ). A friend has an app written 100% UIKit, would love to help make some updates with SwiftUI but haven't figured out how to make my views work in his existing app. Example replacing the nav bar with a custom one like you showed us in a previous video.
Have you done a video or have suggestions on how migrate a UIKit project to SwiftUI? Or how to integrate the two? Would be great to keep the app alive, and integrate tab by tab, instead of writing everything from scratch 100% SwiftUI.
Any ideas are much appreciated.
Thank you!! And thank you for these videos!!
P.S.
Are you available for hire? Contract work?
I’ve done some migrations before. My recommendation is to work backwards, with the root views and tab bar to switch to SwiftUI last. I would start with swapping out the easy screens with the least dependencies. It’s hard to give advice here without seeing the architecture.
KUDOS! thank you very much for sharing your knowledge. Do you intent to explain how to use "Combine" lib? much appreciate. All the best.
Hi Tiago! Yes, I have several Combine tutorials in my Continue Learning playlist. I also have some advanced videos coming soon!
@@SwiftfulThinking Excellent! good to know. Can't wait to learn more from you.
Thank you very much
Great video!! I have a xib in UIKit with dynamic size (need to hide some content on the basis of some logic). How to make sure that in SwiftUI the frame size is updated on the basis of the content of this xib ?
You can set the frame of the UIKit component within the makeUIView function, and you can also set the SwiftUI frame with a regular .frame() modifier!
Nice Video. I am getting the protocol conformance errors as I am converting one conventional swift uwview to swiftui: "cannot convert value of type '(Binding) -> BaseListItemsSummaryCardView_SwiftUI' to expected argument type '(Binding) -> BaseListItemsSummaryCardView_SwiftUI'
Cannot convert value of type '(Binding) -> BaseListItemsSummaryCardView_SwiftUI' to expected argument type '(Binding) -> BaseListItemsSummaryCardView_SwiftUI'
initializer 'init(_:id:rowContent:)' requires that 'Counts' conform to 'MutableCollection'
Initializer 'init(_:id:rowContent:)' requires that 'Counts' conform to 'MutableCollection'
initializer 'init(_:id:rowContent:)' requires that 'Counts' conform to 'RandomAccessCollection'
Initializer 'init(_:id:rowContent:)' requires that 'Counts' conform to 'RandomAccessCollection'" How can I deal with these?
Could you just use an observable object instead of the coordinator?
No, the protocol requires this Coordinator pattern here
@@SwiftfulThinking I just tested an it works if you add vc.vm = in both the makeui and updateui. You don’t even need the coordinator. It then works with a viewmodel. Which is much easier to work with.