Swift - Result Type - Cleaner Network Calls

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 83

  • @guitaripod
    @guitaripod 4 роки тому +3

    Awesome, Sean. Please do more of these non-beginner videos. Big fan of these

    • @seanallen
      @seanallen  4 роки тому +1

      I have a mixture of beginner and non-beginner videos on my to-do list.

  • @hectorsvill
    @hectorsvill 4 роки тому +6

    I definitely need to use result type more often 😄

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

    I had some troubles with passing server direct errors to user with this method but finally it's working, Thank you Sean.

    • @seanallen
      @seanallen  4 роки тому

      Happy to hear it helped, Ahmad!

    • @NITINAGAM
      @NITINAGAM 4 роки тому

      You can use the enum with an associated value. If you have any other solutions, please share.

    • @TheAhmadReza
      @TheAhmadReza 4 роки тому

      @@NITINAGAM Yea I used enum with an associated value...

  • @finalpets
    @finalpets 4 роки тому +1

    Thanks Sean, my network call was incomplete and I didn’t notice that, I definitely you change my code looks more cleaner and easy to read.

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

    Pretty good tutorial, this will make my networking calls a lot more cleaner!

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

    Cleaner networking!
    Thanks, Sean great video!

  • @Ipat639
    @Ipat639 4 роки тому +3

    Great 👍, I love this new feature too.
    In error type, better to use errors conforming to LocalizedError protocol

  • @ivanputeraa
    @ivanputeraa 4 роки тому +1

    Thanks for the tutorial Sean!!!

  • @KelKrom
    @KelKrom 4 роки тому +1

    Awesome explanation, thanks Sean.

  • @lianahaque2512
    @lianahaque2512 4 роки тому +1

    Loving this content! A lot of stuff to learn during these times to stay productive. Thanks, Sean!

    • @donathmm3881
      @donathmm3881 4 роки тому +1

      I think the same! Keep on Sean!

    • @seanallen
      @seanallen  4 роки тому

      Glad you like them, Liana!

  • @Dragonboh1
    @Dragonboh1 4 місяці тому +1

    keep doing what you doing

  • @temokaxniashvili2375
    @temokaxniashvili2375 4 роки тому

    Very Nice Tutorial 🥰

  • @chiraglakhani5434
    @chiraglakhani5434 3 роки тому +1

    Thank you, great tutorial.

  • @rrakesh05
    @rrakesh05 4 роки тому +1

    Awesome tutorial Sean... :)

  • @juliayamamoto1472
    @juliayamamoto1472 4 роки тому +1

    Great video! I usually have two completion handlers: A successful one and a failure one (is that bad?) and I call the one that makes sense. I think I'll change to this solution :) I really liked that! Thanks for the tip. I am a new follower and your channel is helping me a lot!

    • @seanallen
      @seanallen  4 роки тому

      Yes, using Result type is now the preferred way in most scenarios since it was introduced. Happy to hear you are enjoying the channel!

  • @darinburch9043
    @darinburch9043 3 роки тому +1

    DUDE THANK YOU

  • @Jock3R87
    @Jock3R87 4 роки тому +1

    You nailed it 🪓

    • @seanallen
      @seanallen  4 роки тому +1

      Thanks Sagar!

    • @Jock3R87
      @Jock3R87 4 роки тому

      Sean Allen following all your videos... just a suggestion that nowadays Unit testing or TDD approach would be useful and shifting focus from OOPS to POP .... if possible can make real time example using protocol oriented programming with use of DI would be helpful for ios people. Not talking about Hello World kind example but actual xCode small tutorial...

  • @abdulazizalharbi6228
    @abdulazizalharbi6228 4 роки тому +1

    great tutorial and excellent explanation, I really enjoyed watching it, keep it up

  • @cristianm.310
    @cristianm.310 4 роки тому

    Very cool stuff. Out of curiosity, what's in the presentGFAlertOnMainThread method?

    • @seanallen
      @seanallen  4 роки тому +1

      The example project is from my take home project course. That's a method we created to call our custom alert and show it on the main thread. You can find more information about the course and watch the first hour for free at seanallen.teachable.com

    • @cristianmoisei9689
      @cristianmoisei9689 4 роки тому

      Sean Allen thank you, I'll check it out.

  • @guitaripod
    @guitaripod 4 роки тому +1

    The timing of this video is superb lol

  • @nawafb6280
    @nawafb6280 4 роки тому

    really thank you I need it , made the life cleaner and esaier

  • @chrisgrayston6407
    @chrisgrayston6407 4 роки тому +1

    Thanks Sean, love these tutorials

  • @julianbdeveloper
    @julianbdeveloper 4 роки тому

    Hey Sean, I'm certain you've talked about it before, but what Xcode plugin do you use to align your variables like that at 1:42? If anyone knows could you let me know in the reply section?

    • @seanallen
      @seanallen  4 роки тому

      I just tab them over and line them up myself.

    • @julianbdeveloper
      @julianbdeveloper 4 роки тому

      @@seanallen That takes some serious dedication. Thanks for the response Sean and keep up the great work. I learn a lot from you.

    • @seanallen
      @seanallen  4 роки тому +1

      It does... and you'll find a lot of developers that don't like it for that reason. If you do this in a non-personal project, I would expect some pushback on it.

  • @maxspeed2k
    @maxspeed2k 4 роки тому +1

    Thanks Sean!

  • @roushilsingla6325
    @roushilsingla6325 4 роки тому +1

    That's a great help. Thank You ⭐️

    • @seanallen
      @seanallen  4 роки тому +1

      Glad it was helpful!

  • @gjermundification
    @gjermundification 4 роки тому

    @Sean Allen, did your Donny Wals’ book on combine?

    • @seanallen
      @seanallen  4 роки тому

      I have it... haven't had a chance to dive in yet, but soon.

  • @soullesessess
    @soullesessess 4 роки тому +1

    Great video as always. Also, may I know how do you keep your code formatting so clean? My code is messy and it gets even worse when there is a code snippet copied over from other places. Do you use any tool to format the code or just do it manually? Thanks!

    • @seanallen
      @seanallen  4 роки тому +1

      Thanks! I don't use a tool, I just make it a priority to make my code formatted neatly because I'm huge on a readable codebase. Code format is just one part of that.

  • @salithaherath5525
    @salithaherath5525 4 роки тому

    Great video sean.! For Network Call you were using class is there any reason for that or we can use struct?

    • @seanallen
      @seanallen  4 роки тому +1

      In my case, my Network Manager is a singleton, so it's a class

  • @Twenytoo
    @Twenytoo 3 роки тому

    Thanks, my man

  • @JitendraPatel-nb3yf
    @JitendraPatel-nb3yf 4 роки тому +1

    Great tutorial, I like it.

  • @VictorRoldanvictorroldan25
    @VictorRoldanvictorroldan25 4 роки тому +1

    Very useful your videos as always. I have only one recommendation. I think isn’t good create a whole method for each API call, you should create a generic type instead so you wouldn’t have many method with the same code.

    • @seanallen
      @seanallen  4 роки тому +1

      Thanks! For context, this sample code is from my take home project course that's aimed at beginner developers looking to get their first job. For that reason, I demonstrated the network calls the "long way" so I could spell everything out and explain all the details for educational purposes.

  • @dmitriyobidin6049
    @dmitriyobidin6049 3 роки тому

    What about exceptions? Why don't we use throws in th e first place?

  • @tolulopeaboyeji5373
    @tolulopeaboyeji5373 4 роки тому

    Hi @sean, I’m a big fan of ur videos. I implemented result type in my project and I’ve been having a hard time wrapping my head around it.
    What i do before is i create a model for my 200 and 400 response so as to display a toast containing my response but I’ve been unable to decode and pass the 400 error to my enum.
    I really need your help.

    • @seanallen
      @seanallen  4 роки тому

      In this example, we attached a string to our errors. In the networking code (where we call completed with either failure or success), you can check the response.statusCode. So you could do something like if response.statusCode == 401 { completed(failure(.mySpecial401Error)) }. This will pass the failure case with the error attached, which in turn has a string attached that you can display in your toast.

    • @tolulopeaboyeji5373
      @tolulopeaboyeji5373 4 роки тому

      Sean Allen thanks for ur reaponse. I think u dont get my question. What i mean is in scenario where i need to decode both 401error and 200 success. Cause at my work place we always display the decoded message from status code == 401 as a toast

  • @alexchase1856
    @alexchase1856 4 роки тому +1

    I've found this works best when combining Result, DataTask, and Codable with generics. Essentially decoding your network response data as the lhs of your completion closure. I've got plenty of code to share if you want to do a follow up.

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

      Hey Alex, I appreciate that! For context, this sample code is from my take home project course that's aimed at beginner developers looking to get their first job. For that reason, I demonstrated the network calls the "long way" so I could spell everything out and explain all the details for educational purposes.

  • @manfredkernMK
    @manfredkernMK 3 роки тому

    Good video. But I think depending on the use case, the old way is still valid. Imagine, if you have several method calls
    one after the other, which can fail. So, essentially you "jump" out of the success case right after the switch statement and call the next failable method OR you nest calls in the success case. So, that is were guard let comes into play. You first handle all the failure cases of the method calls and after that you can cleanly code your success case.
    So, it's good that we have another way of dealing with failures, Maybe in future there will be some common way on how to use the new result type in the case of several failable methods

  • @scottatkinson6339
    @scottatkinson6339 4 роки тому

    Hey Sean, thanks for the video! Question how do you get your variables so nicely aligned?
    Within the method ScrollViewDidEndDragging the offsetY contentHeight and height variables with the assigned values are spaced out nicely, do you do this manually? Or is it a setting in Xcode that automatically formats them?

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

      I tab them over manually

  • @vamsi3877
    @vamsi3877 4 роки тому +1

    Helpful👏

  • @Cassin1797
    @Cassin1797 4 роки тому

    Hey, Sean ! Can you please explain network calls from closure-related point of view? I don’t really get it, it f*cks me a lot, cause I simply can’t grasp this concept. For example:
    How does completion handler work there? Or, this line : guard let self = self else { return }. I tried to google it, and it’s called strongify self, but I don’t understand what it really does... It would be great if you could explain these moments. Thank you.

    • @seanallen
      @seanallen  4 роки тому

      Hey Alex, this would be way too much to explain by typing in a comment. I'll add it to my video idea list. Although, I do explain in the course where this code sample is pulled from if you're interested. seanallen.teachable.com.

  • @othmanal-otaibi140
    @othmanal-otaibi140 4 роки тому

    Amazing video !! 👍🏼
    Can you please do a video or link us to a source of information about firebase friend invitation request ! For example, user A wants to invite user B as friend, that will not happen till user B accepts the invitation.Currently kinda struggling with friend invitation requests
    Thanks in advance 🙏🏼

  • @3ilz
    @3ilz 4 роки тому

    10/10

  • @EmmaKAlexandra
    @EmmaKAlexandra 4 роки тому +1

    Just in time to replace all this networking code with combine

    • @seanallen
      @seanallen  4 роки тому

      There will still be a TON of UIKit out there for years to come 😀

    • @EmmaKAlexandra
      @EmmaKAlexandra 4 роки тому

      Sean Allen I mean you can use Combine with UIKit too!

  • @davidlintin
    @davidlintin 4 роки тому +1

    I used to pass in a viewController on a network method so I could present an error, this way is much better!

    • @seanallen
      @seanallen  4 роки тому

      Happy to help with a new way to do things, David!

  • @DavidNitzscheBell
    @DavidNitzscheBell 4 роки тому

    This is really good, but I disagree that anything is ambiguous. It's verbose, it's messy, but it's not ambiguous. But, basically, it seems to boil down to something parallel to optionals. With optionals, there are two values: nil or not nil, but with not nil, there is an associated value. Same thing here. There are two result values: success or failure. And each one has an associated value.
    Very useful, thanks, but I'd just discuss it differently....

    • @seanallen
      @seanallen  4 роки тому

      I see what you're saying, and maybe "ambiguous" was too strong of a word. I wanted to demonstrate how, in my opinion, the call site using Result is MUCH more readable and clear.