Retrieving Data Swift 3.0

I am exploring swapping to Backendless, and am working through some of the examples in the SDK documentation. I worked around the non-support of Swift 3.0 using a header file, and maybe that is part of my problem.

Thus far I am able to handle user creation/login/logout fine. I then created the following class.

class Clients : NSObject

{

var objectId: String?

var created: NSDate?

var updated: NSDate?

var name: String?

var location: String?

var street1: String?

var street2: String?

var city: String?

var state: String?

var zip: Int = 0

var lat: Float = 0.0

var lng: Float = 0.0

var enabled: Bool = true

}

Then, in my view controller I create a data store with:

let dsClient = backendless.data .of(Clients.ofClass())

and attempt to retrieve data from the table with:

func findClients()
{
var error: Fault?
let result = dsClient?.find(&error)
if error == nil {
let contacts = result?.getCurrentPage()
print(result)
for obj in contacts!
{
print("(obj)")
}
}
else {
print(“Server reported an error: (error)”)
}

}

It finds the clients, I believe, but I’m not sure what to do with the result. In the console, I get:

<MyAppName.Clients: 0x102e3d070>

<MyAppName.Clients: 0x102e3d450>

There are only two clients in the collection, and my assumption is that those are the responses for each, but I’m unsure how to get usable data out of there.

Hi Richie,

In your “for” loop, the “obj” variable is an instance of the Clients class. So if you cast it to Clients, you should be able to use it as a regular instance of that class (that is access the class’ properties.

Regards,
Mark

Thanks, Mark.