NetworkOperationResult
struct NetworkOperationResult
extension NetworkOperationResult : Equatable, NetworkResult
Basic implementation for handling the result of NetworkOperation action.
The primary requirement for this class is a NetworkStatus result value.
Data and status codes are all optional
-
A network status code often used to hold a value such as a 200 or 404 as found on typical HTTP operations. If this value is -1 it is deemed not in use.
Declaration
Swift
var code: Int -
Any data associated with the result; can be in any format
Declaration
Swift
var data: Data? -
Initializes a new NetworkOperationResult object.
Declaration
Swift
init(_ status: NetworkStatus, data: Data? = nil, statusCode: Int = -1) -
This function makes working with JSON data a bit easier, when it is known that the data represented in the
.dataproperty is JSONDecodable, the instance functionjsonDecodewill perform that work for you by simply having you supply the type to decode it into. Rather than throwing, it will provide you an option of the specified type with anilresult if any errors occurred.struct Name: Codable { var first: String var last: String } let result = NetworkOperationResult(...) let name = result.jsonDecode(Name.self) print("\(name.last), \(name.first)")Declaration
Swift
func jsonDecode<T>(_ type: T.Type) -> T? where T : DecodableParameters
typetypically the class or struct name followed by
.selfReturn Value
an optional of the supplied
Decodableobject; either nil or populated with the contents of the.dataproperty. -
A status flag indicating whether the result was successful, a failure or in progress
Declaration
Swift
var status: NetworkStatus
View on GitHub
Install in Dash
NetworkOperationResult Structure Reference