Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

getting data fields in and out using Swift api

I have an array of UInts that I want to store and retrieve as a data field. I create an NSData object out of the array.
let arrayOfUInts = [UInt] () = [89,90]
let ptr = UnsafeRawPointer(arrayOfUInts)
let nbytesPerUint = MemoryLayout.size(ofValue: UInt())
let data = NSData(bytes: ptr, length: arrayOfUints.count * nbytesPerUint)

I make a parameter array
let recordID = 4
let updateParameters = ["recordID": recordID as AnyObject,
"arrayToStoreAsData":data as AnyObject]
Then call my update query
let operation = Kumulos.call("updateRecord", parameters:updateParameters)
_ = operation.success {(response, operation) in
print("succeeded")
}

When I retrieve the data I do
let recordParameter = ["recordID":recordID as AnyObject] as [String:AnyObject]

  let operation = Kumulos.call("findRecord", parameters:recordParameter)
  _ = operation.success{(response, operation) in
    let recordsFound = response.payload as! NSArray
    if (recordsFound.count > 0) {
       let data = recordsFound[0].object(forKey:"arrayToStoreAsData") as! NSData
  }

The data that comes back is apparently coded somehow and I don't know how to decode it. Can someone tell me how?

Thanks.

Comments

Sign In or Register to comment.