Skip to content

Commit

Permalink
Workarounds for Linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
p2 committed Jan 4, 2017
1 parent c3e3d95 commit 07e4226
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Sources/Models/FHIRAbstractResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ 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
- returns: If possible the appropriate FHIRAbstractBase subclass, instantiated from the given JSON dictionary, Self otherwise
- 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
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/FHIRDecimal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07e4226

Please sign in to comment.