Result pattern in Swift
VEDRAN BUROJEVIĆ
EMAIL: VEDRAN.BUROJEVIC@INFINUM.CO 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
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? VEDRAN.BUROJEVIC@INFINUM.CO @BUROJEVIC
Visit infinum.co or find us on social networks:
infinum.co infinumco infinumco infinum