Swift: Dependency Injection Tutorial (2022) - iOS

Поделиться
HTML-код
  • Опубликовано: 11 июл 2024
  • In this video we take a practical look at dependency injection in Swift by using protocols. Dependency Injection is a powerful pattern to build scalable large applications with decoupled logic. It allows objects to use common functionality in an agnostic way; such that one object does not know where the functionality comes from. We'll be working in Xcode 12 and Swift 5 to demonstrate this with multiple targets.
    💻 Source Code: / iosacademy
    🎥 Subscribe for more: ruclips.net/user/iOSAcademy?su...
    😎 Like my teaching style? Check out some of my most popular courses! courses.iosacademy.io
    ** Popular Series
    Building Instagram: courses.iosacademy.io/p/build...
    Building TikTok: / @iosacademy
    SwiftUI for Beginners: ios-academy.teachable.com/p/s...
    ** Get Skillshare free for 2 Months and learn iOS
    www.skillshare.com/r/user/afraz
    ** Manage all your investments from app earnings on Betterment!
    bit.ly/3eBwlI9
    ** Grow your own RUclips tech channel with TubeBuddy:
    www.tubebuddy.com/iosacademy
    *Timestamps*
    0:00 Swift Dependency Injection
    0:49 Create Project
    1:50 Create Button
    3:24 Create Xcode Target
    4:28 Create API Caller
    6:17 Create New Target
    9:39 Decode API Response
    10:40 Create Protocol
    13:19 Pass Dependency
    18:00 Finalize Data
    19:30 Set Up TableView
    22:05 Dependency Injection Review
    24:14 Wrap Up / Outro
    #swift #dependency #iOS

Комментарии • 70

  • @awsysumer3814
    @awsysumer3814 2 года назад +17

    Out of million tutorials about DI, this one explains it crystal clear and in a very simple way to understand. Thank you so much. Keep it up 👍🏻

  • @hadyhelal6626
    @hadyhelal6626 2 года назад +5

    Why did you use singleton despite you used dependency injection? i know that one of dependency injection benefit is to remove singleton!!

  • @TheSpiralnotizblock
    @TheSpiralnotizblock 2 года назад +4

    I was waiting so hard for this! Thank you so much

  • @zb1123
    @zb1123 2 года назад +4

    Fantastic video - clear and concise! Cheers!

  • @vinnygen6632
    @vinnygen6632 2 года назад +3

    Been waiting for this! Thanks a lot!

    • @iOSAcademy
      @iOSAcademy  2 года назад

      Hope you enjoyed it!

    • @peaceL2626
      @peaceL2626 2 года назад

      @@iOSAcademy hey, Do you have learning path for beginner to advance like this topics(di,reactive programming etc)

  • @apoorvas99
    @apoorvas99 2 года назад +2

    Loved it! Thank You so much.

  • @user-zh3el2yr6h
    @user-zh3el2yr6h 2 года назад +2

    Smashing that like button even before watching the video. Thank you!

  • @BharatKumar-xk6lq
    @BharatKumar-xk6lq 2 года назад +4

    Thanks alot brother 👍 perfect understandable explination 💗 loads of love 💗😍

  • @DaveJacobseniOS
    @DaveJacobseniOS 2 года назад

    suuuuper helpful. thanks!

  • @laurapotter6321
    @laurapotter6321 2 года назад +2

    Thank you for this wonderful tutorial! One question: so the in the dataFetchable protocol, the function needs to have the exact same name with the one inside ApiCaller right ?

  • @nemotv6623
    @nemotv6623 2 года назад +5

    DI with MVVM example? Awesome video btw, thanks

  • @phantuananh2163
    @phantuananh2163 Год назад

    Impressive!!!

  • @chaitanyakella7937
    @chaitanyakella7937 2 года назад +1

    Beautiful

  • @johncerpa3782
    @johncerpa3782 2 года назад +1

    Excellent

  • @JP-ks3kh
    @JP-ks3kh 2 года назад +2

    This is a great tutorial...Thanks a lot! Moarrrr plzzzzz.

  • @raychen4458
    @raychen4458 Год назад

    please can we have another DI tutorials that talks more in depth concepts and how to work with MVVM
    Much appreciated !!!

  • @tientranminh9564
    @tientranminh9564 2 года назад

    Pls make a tutorial about distribute app over the air

  • @soromiso
    @soromiso 2 года назад +2

    Thanks

  • @CJWhitaker
    @CJWhitaker 2 года назад

    How do you inject to the home view controller when it's embedded in a Navigation Controller?

  • @ahopdanzer
    @ahopdanzer 2 года назад +1

    brilliant di tutorial

  • @ahmetbugraozcan6742
    @ahmetbugraozcan6742 Год назад

    It was great video but I have different question. What should we do when we require a data to multiple places? I was thinking dependency injection is related to this but it seems it doesnt so I am little confused.

  • @johnmathew2120
    @johnmathew2120 2 года назад +3

    Hi, Thanks for great lesson with easy practical sample. I have one doubt, This injecting will works only on Targets or it will work classes too?

    • @iOSAcademy
      @iOSAcademy  2 года назад +1

      Youre welcome. Yep it works for both

    • @johnmathew2120
      @johnmathew2120 2 года назад

      @@iOSAcademy Thank you 🙂🙂

  • @cesaralcantara1341
    @cesaralcantara1341 2 года назад +3

    Can you possibly explain the @escaping closures and callback and the reason for this instead of making the function return something? New to iOS development

    • @novo4249
      @novo4249 2 года назад +4

      Hi Cesar, using callback function to return a value is a common approach to achieve asynchronous function in programming. In this case, the function have to be asynchronous as the network API call is not returning the value immediately. @escaping closure is just the Swift way of implementing callback.

    • @cesaralcantara1341
      @cesaralcantara1341 2 года назад

      @@novo4249 thank you so much Hans! I appreciate it!

  • @kalpeshjethva598
    @kalpeshjethva598 Год назад

    I have multiple environments how can I manage them?

  • @tokero5199
    @tokero5199 2 года назад +1

    This was a very nice tutorial. I know it's slightly off topic but how would you handle dependencies of your separated out targets. Let's say you network module depends on alamofire but you do not want you main app to depend on alamofire.

    • @ApoCaLypSeXVII
      @ApoCaLypSeXVII 2 года назад

      I mean correct me if I'm wrong but once you import 3rd party dependencies to assist with backend network calls wouldn't it now become a global asset to the whole project? Anything having to do with the API would require you importing in alamofire for each file no?

    • @RajrkSunny
      @RajrkSunny Год назад

      @@ApoCaLypSeXVII I think we can also setup 3rd party for individual targets.

  • @swiftMyDay
    @swiftMyDay 2 года назад +2

    I broke my iPhone smashing the like button 😩

  • @artikes9519
    @artikes9519 2 года назад +2

    Great Video! Isn't that dependency inversion?

  • @harivigneshks8817
    @harivigneshks8817 2 года назад +2

    Brother for learning iOS development do we need Mac laptop or any other alternatives and if we want to buy apple laptop what OS needs to be purchased bro

    • @iOSAcademy
      @iOSAcademy  2 года назад

      Yes you need a mac with macos

    • @harivigneshks8817
      @harivigneshks8817 2 года назад

      @@iOSAcademy what OS Catalina or bigsur

    • @harivigneshks8817
      @harivigneshks8817 2 года назад

      @@iOSAcademy can we do swift programming in virtual machines

  • @Oisinkelly308
    @Oisinkelly308 2 года назад +1

    Should 256gb be enough for balancing college work and xcode projects or should i invest in 512gb storage? I am going to be purchasing a macbook air soon and don’t know how much storage xcode takes up. Thanks

    • @maqusss
      @maqusss 2 года назад +2

      255gb is definitely to small. U need at least 512gb.

    • @iOSAcademy
      @iOSAcademy  2 года назад +1

      Id invest in 512

    • @johncerpa3782
      @johncerpa3782 2 года назад +2

      16 gb of ram, minimum

    • @Oisinkelly308
      @Oisinkelly308 2 года назад +3

      @@johncerpa3782 ordered 512gb ssd 16gb ram

  • @dhikaaditya1920
    @dhikaaditya1920 Год назад

    kit

  • @JoeEnos
    @JoeEnos 2 года назад

    I’ve only been doing iOS development a few weeks, glad to see I’m not alone with Xcode being really flaky. Visual Studio isn’t perfect, but it seems way more stable and consistent.

  • @evgenykravtsov2157
    @evgenykravtsov2157 2 года назад +1

    import UsefullKit

  • @iOSAcademy
    @iOSAcademy  2 года назад

    Enjoy my teaching style? Check out iOS Academy+ at iosacademy.io/plus

  • @sirfetchd9829
    @sirfetchd9829 2 года назад +1

    this was way too fast

  • @mumble57558
    @mumble57558 2 года назад

    👍👍👍