قالب وردپرس درنا توس
Home / IOS Development / Is it possible to send an enum that holds an error string value through a completion manager and access the string? : iOSProgramming

Is it possible to send an enum that holds an error string value through a completion manager and access the string? : iOSProgramming



I'm trying to set up an enum for the success and failure of a network request. What I have made is:

  enum Outcome {
case .success
case. wrong (strict)
}

latest func getData (completion: @escaping ((Outcome) -> Void)) {
completion ("error: request timed out")
}

was data: [Data]
was wrong: String = zero

manager.getData (completion: {result in
change result.outcome {
case. success:
data = result data
case. error:
// Unsure about how to get inline string
}
})

I may have misunderstood if this is possible with enums after some reading, but in the case of a network request error, I will send the error message with the error message for the error contained in. I have attempted to get this setup but have no idea how you can access the built-in string. After a little more reading, does it seem that this cannot be done or is it wrong?


Source link