Created
November 17, 2016 10:52
-
-
Save yageek/dd491dec6428fd95f495ddc5fa242926 to your computer and use it in GitHub Desktop.
ProcedureKit compilation error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class JSONSerializationProcedure<T: JSONObject>: Procedure, ResultInjection { | |
public var requirement: PendingValue<URLRequest> = .pending | |
public var result: PendingValue<HTTPRequirement<Data>> = .pending | |
private var object: ResourceResult<T> | |
public init(object: ResourceResult<T>) { | |
self.object = object | |
super.init() | |
} | |
public override func execute() { | |
guard let require = requirement.value else { | |
finish(withError: ProcedureKitError.requirementNotSatisfied()) | |
return | |
} | |
var anyData: Any? | |
switch object { | |
case let .singleton(value): | |
anyData = value.JSON | |
case let .collection(objects): | |
anyData = objects.flatMap{ $0.JSON } | |
} | |
guard let finalObject = anyData else { | |
finish(withError: MediaServerAPIError.SerializingError.marshal) | |
return | |
} | |
do { | |
let data = try JSONSerialization.data(withJSONObject: finalObject, options: []) | |
result = .ready(HTTPRequirement(payload: data, request: require)) | |
finish() | |
} catch let error { | |
finish(withError: error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment