Infinum iOS Talks #4 - Making your Swift networking code more awesome with Result

17
Result pattern in Swift VEDRAN BUROJEVIĆ EMAIL: [email protected] TWITTER: @VBUROJEVIC

Transcript of Infinum iOS Talks #4 - Making your Swift networking code more awesome with Result

Result pattern in Swift

VEDRAN BUROJEVIĆ

EMAIL: [email protected] TWITTER: @VBUROJEVIC

01HANDLING ERRORS IN SWIFT

👍

Swift error handling with try, catch, do and throw works

nicely with synchronous code

🤔

But what about networking calls which are asynchronous?

🚀

DEMO TIME (NETWORKING WITHOUT RESULT PATTERN)

02RESULT PATTERN HTTPS://GITHUB.COM/ANTITYPICAL/RESULT

Swift 2.0 introduces error handling via throwing and catching ErrorType.

Result accomplishes the same goal by encapsulating the result instead of hijacking control flow.

RESULT DECLARATION

RESULT IS SIMILAR TO SWIFT’S OPTIONAL

HANDLING RESULT

You can use Result whenever operation has a possibility of

failure

You can even use Higher Order Functions such as map and

flatMap

🚀

DEMO TIME (NETWORKING WITH RESULT PATTERN)

💻

EXAMPLE REPO https://github.com/vburojevic/ResultExample

📱🎉

THAT’LL BE ALL FOLKS!THANKS FOR LISTENING!

Any questions? [email protected] @BUROJEVIC

Visit infinum.co or find us on social networks:

infinum.co infinumco infinumco infinum