Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Improved Dictionary Bridging
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyKJohnson committed Dec 13, 2016
1 parent 349605e commit d8a6261
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
29 changes: 17 additions & 12 deletions Sources/Bridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ extension Double: _OCKBridgable {
}
}

extension Dictionary {
func bridge() -> NSDictionary {
var newDictionary: [NSString: Any] = [:]

for (key,value) in self {
if let stringKey = key as? String {
newDictionary[stringKey.bridge()] = value
} else if let nsstringKey = key as? NSString {
newDictionary[nsstringKey] = value
}
}
return newDictionary._bridgeToObjectiveC()
}
}


#if !os(Linux)

typealias NSErrorUserInfoType = [AnyHashable: Any]
Expand All @@ -82,12 +98,6 @@ extension Double: _OCKBridgable {
}
}

extension Dictionary {
func bridge() -> NSDictionary {
return self as NSDictionary
}
}

extension Array {
func bridge() -> NSArray {
return self as NSArray
Expand Down Expand Up @@ -136,12 +146,7 @@ extension Double: _OCKBridgable {
}
}

extension Dictionary {
func bridge() -> NSDictionary {
return self._bridgeToObjectiveC()
}
}


extension Array {
public func bridge() -> NSArray {
return self._bridgeToObjectiveC()
Expand Down
5 changes: 5 additions & 0 deletions Sources/CKModifyRecordsURLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class CKModifyRecordsURLRequest: CKURLRequest {
if let zoneID = zoneID {
parameters["zoneID"] = zoneID.dictionary.bridge()
}


requestProperties = parameters
}
Expand Down Expand Up @@ -114,7 +115,11 @@ class CKModifyRecordsURLRequest: CKURLRequest {
recordDictionary["parent"] = ["recordName": parent.recordID.recordName.bridge()].bridge()
}


let operationDictionary: [String: Any] = ["operationType": operationType.bridge(), "record": recordDictionary.bridge() as NSDictionary]



return operationDictionary
})

Expand Down
3 changes: 3 additions & 0 deletions Sources/CKRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ extension CKRecord {
}
}

print(fieldsDictionary)


return fieldsDictionary

}
Expand Down
6 changes: 3 additions & 3 deletions Sources/CKURLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class CKURLRequest: NSObject {
if let properties = requestProperties {

// While JSON Parsing doesn't support Swift Types on Linux, Use Jay
//let jsonData: Data = try! JSONSerialization.data(withJSONObject: properties, options: [])
let jsonData: Data = try! JSONSerialization.data(withJSONObject: properties, options: [])

let data = try! Jay(formatting: .prettified).dataFromJson(any: properties) // [UInt8]
let jsonData = Data(bytes: data)
// let data = try! Jay(formatting: .prettified).dataFromJson(any: properties) // [UInt8]
// let jsonData = Data(bytes: data)

urlRequest.httpBody = jsonData
urlRequest.httpMethod = "POST"
Expand Down

0 comments on commit d8a6261

Please sign in to comment.