Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4 migration #16

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion Sources/Client/FHIRMinimalServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ open class FHIRMinimalServer: FHIRServer {
Main initializer. Makes sure the base URL ends with a "/" to facilitate URL generation later on.
*/
public required init(baseURL base: URL, auth: [String: Any]? = nil) {
if let last = base.absoluteString.characters.last, last != "/" {
if let last = base.absoluteString.last, last != "/" {
baseURL = base.appendingPathComponent("/")
}
else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Client/FHIROperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class FHIROperation: CustomStringConvertible {
var instance: Resource? {
didSet {
if let inst = instance {
type = type(of: inst)
type = Swift.type(of: inst)
context = .instance
}
}
Expand Down Expand Up @@ -181,5 +181,5 @@ open class FHIROperation: CustomStringConvertible {


/// Alias to `FHIROperation` for neat operation usage.
public typealias $ = FHIROperation
public typealias `$` = FHIROperation

4 changes: 2 additions & 2 deletions Sources/Client/FHIRSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ open class FHIRSearch
// expand
let qry = query.expand(extra)
if let type = profileType {
if qry.characters.count > 0 {
if qry.count > 0 {
return "\(type.resourceType)?\(qry)"
}
return type.resourceType
}
if qry.characters.count > 0 {
if qry.count > 0 {
return "?\(qry)"
}
return ""
Expand Down
6 changes: 3 additions & 3 deletions Sources/Client/FHIRServerDataResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ extension FHIRServerResponse {
// inspect ETag header
if var etag = headers["ETag"] {
if etag.hasPrefix("W/") {
etag = etag[etag.index(etag.startIndex, offsetBy: 2)..<etag.endIndex]
etag = String(etag[etag.index(etag.startIndex, offsetBy: 2)..<etag.endIndex])
}
if etag.hasPrefix("\"") {
etag = etag[etag.index(etag.startIndex, offsetBy: 1)..<etag.endIndex]
etag = String(etag[etag.index(etag.startIndex, offsetBy: 1)..<etag.endIndex])
}
if etag.hasSuffix("\"") {
etag = etag[etag.startIndex..<etag.index(etag.endIndex, offsetBy: -1)]
etag = String(etag[etag.startIndex..<etag.index(etag.endIndex, offsetBy: -1)])
}
resource.meta = resource.meta ?? Meta()
resource.meta!.versionId = FHIRString(etag)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Client/Patient+SMART.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ extension HumanName {

var parts = [String]()
if let prefix = prefix {
parts.append(contentsOf: prefix.filter() { $0.string.characters.count > 0 }.map() { $0.string })
parts.append(contentsOf: prefix.filter() { $0.string.count > 0 }.map() { $0.string })
}
if let given = given {
parts.append(contentsOf: given.filter() { $0.string.characters.count > 0 }.map() { $0.string })
parts.append(contentsOf: given.filter() { $0.string.count > 0 }.map() { $0.string })
}
if let family = family?.string, family.characters.count > 0 {
if let family = family?.string, family.count > 0 {
parts.append(family)
}
if let suffix = suffix {
parts.append(contentsOf: suffix.filter() { $0.string.characters.count > 0 }.map() { $0.string })
parts.append(contentsOf: suffix.filter() { $0.string.count > 0 }.map() { $0.string })
}
guard parts.count > 0 else {
return nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/Reference+Resolving.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ extension Reference {
/** Strips the leading hash "#" symbol, if it's there, in order to perform a contained resource lookup. */
func processedReferenceIdentifier() -> String? {
if let ref = reference?.string, "#" == ref[ref.startIndex] {
return ref[ref.index(ref.startIndex, offsetBy: 1)..<ref.endIndex]
return String(ref[ref.index(ref.startIndex, offsetBy: 1)..<ref.endIndex])
}
return reference?.string
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/Base64Binary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public struct Base64Binary: FHIRPrimitive, FHIRJSONType, ExpressibleByStringLite
// MARK: - Printable, Equatable and Comparable

public var description: String {
return "<Base64Binary; \(value.characters.count) chars>"
return "<Base64Binary; \(value.count) chars>"
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/Claim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ open class ClaimDiagnosis: BackboneElement {
self.diagnosisReference = value
}
else {
fhir_warn("Type “\(type(of: diagnosis))” for property “\(diagnosis)” is invalid, ignoring")
fhir_warn("Type “\(Swift.type(of: diagnosis))” for property “\(diagnosis)” is invalid, ignoring")
}
self.sequence = sequence
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Models/DateAndTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ class DateAndTimeParser {
var tzHrMin = hourStr
var tzhour = 0
var tzmin = 0
if 2 == hourStr.characters.count {
if 2 == hourStr.count {
tzhour = Int(hourStr) ?? 0
if nil != scanner.fhir_scanString(":"), let tzm = scanner.fhir_scanInt() {
tzHrMin += (tzm < 10) ? ":0\(tzm)" : ":\(tzm)"
Expand All @@ -877,9 +877,9 @@ class DateAndTimeParser {
}
}
}
else if 4 == hourStr.characters.count {
tzhour = Int(hourStr.substring(to: hourStr.index(hourStr.startIndex, offsetBy: 2)))!
tzmin = Int(hourStr.substring(from: hourStr.index(hourStr.startIndex, offsetBy: 2)))!
else if 4 == hourStr.count {
tzhour = Int(hourStr[..<hourStr.index(hourStr.startIndex, offsetBy: 2)])!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to tab indentation

tzmin = Int(hourStr[hourStr.index(hourStr.startIndex, offsetBy: 2)...])!
}

let offset = tzhour * 3600 + tzmin * 60
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/ExplanationOfBenefit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ open class ExplanationOfBenefitDiagnosis: BackboneElement {
self.diagnosisReference = value
}
else {
fhir_warn("Type “\(type(of: diagnosis))” for property “\(diagnosis)” is invalid, ignoring")
fhir_warn("Type “\(Swift.type(of: diagnosis))” for property “\(diagnosis)” is invalid, ignoring")
}
self.sequence = sequence
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/FHIRAbstractBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public func instantiate<T: FHIRAbstractBase>(type: T.Type, for key: String, in j

// correct type?
guard let arr = exist as? [T.JSONType] else {
errors.append(FHIRValidationError(key: key, wants: Array<T.JSONType>.self, has: type(of: exist)))
errors.append(FHIRValidationError(key: key, wants: Array<T.JSONType>.self, has: Swift.type(of: exist)))
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Models/FHIRAbstractResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ open class FHIRAbstractResource: FHIRAbstractBase {
super.populate(from: json, context: &context)
if let type = json["resourceType"] as? String {
context.insertKey("resourceType")
if type != type(of: self).resourceType {
context.addError(FHIRValidationError(key: "resourceType", problem: "should be “\(type(of: self).resourceType)” but is “\(type)”"))
if type != Swift.type(of: self).resourceType {
context.addError(FHIRValidationError(key: "resourceType", problem: "should be “\(Swift.type(of: self).resourceType)” but is “\(type)”"))
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/FHIRDecimal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public struct FHIRDecimal: FHIRPrimitive, LosslessStringConvertible, Expressible
#if os(Linux)
self.init(Decimal(json))
#else
if let _ = json.stringValue.characters.index(of: ".") {
if let _ = json.stringValue.index(of: ".") {
self.init(stringLiteral: String(format: "%.15g", json.doubleValue))
}
else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Models/FHIREnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public func createEnum<E: RawRepresentable>(type: E.Type, for key: String, in js

// correct type?
guard let value = exist as? E.RawValue else {
context.addError(FHIRValidationError(key: key, wants: E.RawValue.self, has: type(of: exist)))
context.addError(FHIRValidationError(key: key, wants: E.RawValue.self, has: Swift.type(of: exist)))
return nil
}

Expand Down Expand Up @@ -61,7 +61,7 @@ public func createEnums<E: RawRepresentable>(of type: E.Type, for key: String, i

// correct type?
guard let val = exist as? [E.RawValue] else {
context.addError(FHIRValidationError(key: key, wants: Array<E.RawValue>.self, has: type(of: exist)))
context.addError(FHIRValidationError(key: key, wants: Array<E.RawValue>.self, has: Swift.type(of: exist)))
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Models/FHIRType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public func createInstance<P: FHIRJSONType>(type: P.Type, for key: String, in js
context.insertKey(key)

guard let val = exist as? P.JSONType else {
context.addError(FHIRValidationError(key: key, wants: P.JSONType.self, has: type(of: exist)))
context.addError(FHIRValidationError(key: key, wants: P.JSONType.self, has: Swift.type(of: exist)))
return nil
}

Expand Down Expand Up @@ -278,7 +278,7 @@ public func createInstances<P: FHIRJSONType>(of type: P.Type, for key: String, i

// correct type, also for _key?
guard let val = exist as? [P.JSONType] else {
context.addError(FHIRValidationError(key: key, wants: Array<P.JSONType>.self, has: type(of: exist)))
context.addError(FHIRValidationError(key: key, wants: Array<P.JSONType>.self, has: Swift.type(of: exist)))
return nil
}

Expand All @@ -289,7 +289,7 @@ public func createInstances<P: FHIRJSONType>(of type: P.Type, for key: String, i
primitiveExtensions = primitivesCorrect
}
else {
context.addError(FHIRValidationError(key: "_\(key)", wants: Array<FHIRJSON?>.self, has: type(of: primitivesExist)))
context.addError(FHIRValidationError(key: "_\(key)", wants: Array<FHIRJSON?>.self, has: Swift.type(of: primitivesExist)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/MedicationDispense.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ open class MedicationDispense: DomainResource {
self.medicationReference = value
}
else {
fhir_warn("Type “\(type(of: medication))” for property “\(medication)” is invalid, ignoring")
fhir_warn("Type “\(Swift.type(of: medication))” for property “\(medication)” is invalid, ignoring")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ open class Signature: Element {
self.whoReference = value
}
else {
fhir_warn("Type “\(type(of: who))” for property “\(who)” is invalid, ignoring")
fhir_warn("Type “\(Swift.type(of: who))” for property “\(who)” is invalid, ignoring")
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Models/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ open class TaskInput: BackboneElement {
self.valueMeta = value
}
else {
fhir_warn("Type “\(type(of: value))” for property “\(value)” is invalid, ignoring")
fhir_warn("Type “\(Swift.type(of: value))” for property “\(value)” is invalid, ignoring")
}
}

Expand Down Expand Up @@ -797,7 +797,7 @@ open class TaskOutput: BackboneElement {
self.valueMeta = value
}
else {
fhir_warn("Type “\(type(of: value))” for property “\(value)” is invalid, ignoring")
fhir_warn("Type “\(Swift.type(of: value))” for property “\(value)” is invalid, ignoring")
}
}

Expand Down
Loading