Skip to content

Commit 07e4226

Browse files
committed
Workarounds for Linux
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.
1 parent c3e3d95 commit 07e4226

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

Sources/Models/FHIRAbstractResource.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ open class FHIRAbstractResource: FHIRAbstractBase {
3333

3434
- note: If the factory does not return a subclass of the receiver, will discard the factory-created instance and use
3535
`self.init(json:owner:)` instead.
36+
- todo: Disabled factory use on Linux for now since it crashes the compiler as of Swift 3.0.1
3637

3738
- parameter json: A FHIRJSON decoded from a JSON response
3839
- parameter owner: The FHIRAbstractBase owning the new instance, if appropriate
3940
- returns: If possible the appropriate FHIRAbstractBase subclass, instantiated from the given JSON dictionary, Self otherwise
4041
- throws: FHIRValidationError
4142
*/
4243
public final override class func instantiate(from json: FHIRJSON, owner: FHIRAbstractBase?) throws -> Self {
44+
#if !os(Linux)
4345
if let type = json["resourceType"] as? String {
4446
return try factory(type, json: json, owner: owner, type: self)
4547
}
48+
#endif
4649
return try self.init(json: json, owner: owner) // must use 'required' init with dynamic type
4750
}
4851

Sources/Models/FHIRDecimal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public struct FHIRDecimal: FHIRPrimitive, LosslessStringConvertible, Expressible
7171

7272
public func asJSON(errors: inout [FHIRValidationError]) -> JSONType {
7373
#if os(Linux)
74-
return doubleValue
74+
return Double("\(decimal)") ?? 0.0
7575
#else
7676
return decimal as NSNumber
7777
#endif

0 commit comments

Comments
 (0)