Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

swift get error from the from completion

let result = divide(10, by: 2) // Result<Int, DivisionError>
let mapSuccess = result.map { divide($0, by: 2) } // Result<Result<Int, DivisionError>, DivisionError>
let flatMapSuccess = result.flatMap { divide($0, by: 2) } // Result<Int, DivisionError>
let mapFailure = result.mapError { NSError(domain: $0.localizedDescription, code: 0, userInfo: nil) }
let flatMapFailure = result.flatMapError { .failure(NSError(domain: $0.localizedDescription, code: 0, userInfo: nil)) }
Source by theswiftdev.com #
 
PREVIOUS NEXT
Tagged: #swift #error #completion
ADD COMMENT
Topic
Name
8+9 =