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...

КОМЕНТАРІ • 33

  • @ncba
    @ncba 2 роки тому +4

    UIKit works so flawlessly (I started on SwiftUI and use it when need be). I hope thats where SwiftUI grows to

  • @noamif
    @noamif 2 роки тому +3

    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!

  • @GGGGGG-qj2un
    @GGGGGG-qj2un Рік тому

    I'm impressed. I'm too old for this stuff. I wish I were young. There was no OS when I was a teen.

  • @cinquain0
    @cinquain0 2 роки тому +3

    Truly wonderful video. I’ve used viewrepresentables before but still learned something new. Great job Nick

  • @tchendoh
    @tchendoh Рік тому +1

    Thanks a lot! Kind of scary at first but it all makes sense.

  • @marclutke1900
    @marclutke1900 2 роки тому +1

    Now my understanding is much better than before. Maybe it helps me to solve my Custom Annotation problem. 😅

  • @kasunjayasekara3052
    @kasunjayasekara3052 2 роки тому +2

    Thank you very much it's an amazing explanation.

  • @JZ-xc8hu
    @JZ-xc8hu Рік тому

    thank you , i can easily understand in a short time

  • @BruceCichowlas
    @BruceCichowlas 2 роки тому

    That was really excellent and just what I needed today!

  • @rungxanh2901
    @rungxanh2901 9 місяців тому

    What a gem!

  • @AADITYAAA
    @AADITYAAA 2 роки тому +1

    this is so helpful thanks a ton!!

  • @ShooMPozitiV
    @ShooMPozitiV 2 роки тому

    If youtube let me like this video 1000 times - I've did it )

  • @mackmelodeeofficial
    @mackmelodeeofficial 10 місяців тому

    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)

  • @paulancajima
    @paulancajima 2 роки тому

    Thank you

  • @alexvaiman4966
    @alexvaiman4966 6 місяців тому

    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 )))

  • @AdjieSatryo
    @AdjieSatryo Рік тому

    Thank you for the explanation nick! Does it also work with the UIKit view gesture, for example pinch zoom

  • @shekharsaini9069
    @shekharsaini9069 Рік тому

    Thanks 👍👍👍🙏👍🙏

  • @KimbrellBrad
    @KimbrellBrad 2 роки тому +1

    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!

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      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?

  • @worldofqurani1364
    @worldofqurani1364 Рік тому

    is it worthing to write a 100 line for only a placeholder Color ! I would go with the regular swift ui one

  • @istalzer2
    @istalzer2 Рік тому

    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?

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому +2

      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.

  • @tmjromao
    @tmjromao 2 роки тому +1

    KUDOS! thank you very much for sharing your knowledge. Do you intent to explain how to use "Combine" lib? much appreciate. All the best.

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому +2

      Hi Tiago! Yes, I have several Combine tutorials in my Continue Learning playlist. I also have some advanced videos coming soon!

    • @tmjromao
      @tmjromao 2 роки тому

      @@SwiftfulThinking Excellent! good to know. Can't wait to learn more from you.

  • @hemantstha4144
    @hemantstha4144 Рік тому

    Thank you very much

  • @cdhello4413
    @cdhello4413 2 роки тому

    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 ?

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      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!

  • @HumbleHustle101
    @HumbleHustle101 2 роки тому

    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?

  • @yourgflikesit
    @yourgflikesit Рік тому

    Could you just use an observable object instead of the coordinator?

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому +1

      No, the protocol requires this Coordinator pattern here

    • @yourgflikesit
      @yourgflikesit Рік тому

      @@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.