From 07e422687da276590dac1d204eaa0d97e26b212f Mon Sep 17 00:00:00 2001 From: Pascal Pfiffner Date: Thu, 5 Jan 2017 00:27:56 +0100 Subject: [PATCH] Workarounds for Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This disables FHIRAbstractResource’s `instantiate()` method because of a compiler crash (argument type mismatch when it calls out to the factory). Also adds a somewhat nasty conversion from `Decimal` to `Double` – needed while NSJSONSerialization works differently on Linux and macOS. --- Sources/Models/FHIRAbstractResource.swift | 3 +++ Sources/Models/FHIRDecimal.swift | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/Models/FHIRAbstractResource.swift b/Sources/Models/FHIRAbstractResource.swift index fad57b4c..035a3b2f 100644 --- a/Sources/Models/FHIRAbstractResource.swift +++ b/Sources/Models/FHIRAbstractResource.swift @@ -33,6 +33,7 @@ open class FHIRAbstractResource: FHIRAbstractBase { - note: If the factory does not return a subclass of the receiver, will discard the factory-created instance and use `self.init(json:owner:)` instead. + - todo: Disabled factory use on Linux for now since it crashes the compiler as of Swift 3.0.1 - parameter json: A FHIRJSON decoded from a JSON response - parameter owner: The FHIRAbstractBase owning the new instance, if appropriate @@ -40,9 +41,11 @@ open class FHIRAbstractResource: FHIRAbstractBase { - throws: FHIRValidationError */ public final override class func instantiate(from json: FHIRJSON, owner: FHIRAbstractBase?) throws -> Self { + #if !os(Linux) if let type = json["resourceType"] as? String { return try factory(type, json: json, owner: owner, type: self) } + #endif return try self.init(json: json, owner: owner) // must use 'required' init with dynamic type } diff --git a/Sources/Models/FHIRDecimal.swift b/Sources/Models/FHIRDecimal.swift index 4800ea59..7f74492a 100644 --- a/Sources/Models/FHIRDecimal.swift +++ b/Sources/Models/FHIRDecimal.swift @@ -71,7 +71,7 @@ public struct FHIRDecimal: FHIRPrimitive, LosslessStringConvertible, Expressible public func asJSON(errors: inout [FHIRValidationError]) -> JSONType { #if os(Linux) - return doubleValue + return Double("\(decimal)") ?? 0.0 #else return decimal as NSNumber #endif