Get Data after query

How do i get the class field data after query ?

Did you read the documentation?

Ya but not quite get it

func findContactByName() {

let whereClause = "name = 'Jack Daniels'"
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
 
var error: Fault?
let bc = backendless.data.of(Contact.ofClass()).find(dataQuery, fault: &error)
if error == nil {
    print("Contacts have been found: \(bc.data)")
}
else {
    print("Server reported an error: \(error)")
}

}

After query where can i get the data from the class from a specific field

“bc” is an instance of BackendlessCollection. It contains the objects returned by the server.

but how can i get the a more specific field ?

I have found the data but how can i extract it ?

https://backendless.com/feature-16-data-retrieval-api-how-to-load-objects-from-an-mbaas-storage/

Thanks a lot :slight_smile:

I have try yours but having error in restaurant.name

for restaurant in currentPage {
println(“Restaurant name = (restaurant.name)”)
}

I have try yours but having error in restaurant.name

for restaurant in currentPage {
println(“Restaurant name = (restaurant.name)”)
}

In Swift 2 you need to cast the object:

for restaurant in currentPage as! [Restaurant] {
println("Restaurant <\(restaurant.ofClass())> name = \(restaurant.name), cuisine = \(restaurant.cuisine)")
}

Thanks , backendless support was the best XD

Need your help agn after changing i get this error

fatal error: NSArray element failed to match the Swift Array Element type

Need your help agn after changing i get this error

fatal error: NSArray element failed to match the Swift Array Element type

See the comment for the article: https://backendless.com/feature-16-data-retrieval-api-how-to-load-objects-from-an-mbaas-storage/#comment-2492720821

Now, this is a client-side coding error. Sorry, I cannot help you with that. There should be plenty of resources where you can find this means. This support is limited to our APIs and the backend questions.

It seems like error when doing casting like this

for restaurant in currentPage as! [Restaurant] {
println("Restaurant <\(restaurant.ofClass())> name = \(restaurant.name), cuisine = \(restaurant.cuisine)")
}

Did you see the comment on the article page from another user?

Saw that if i do his way

i am getting this error

Could not cast value of type ‘__NSDictionaryM’ (0x10372fd38) to ‘***’ (0x100aa05f0).

Hi Khoo,

The examples in Backendless API Cookbook (https://backendless.com/blog-a-feature-a-day-challenge/) have been wrote on Swift 1.0. We are going to fix them asap.

Here is github repository with all examples of Backendless API Cookbook which have been fixed with Swift 2 - https://github.com/Backendless/BlogFeatureDay-iOS. All of them work fine, you can download them, try them and compare with your project.

With problem you’ve got an error: I added appId & secretKey of my app in F16RetrievingData project, it works for me, you also can try it.

A project F17DataPaging demonstrates paging of BackendlessCollection object - https://github.com/Backendless/BlogFeatureDay-iOS/tree/master/F17DataPaging/F17DataPagingSwift

Hope it also will be helpful for you.

Regards,
Slava

i changed your applciation id and secrect it works on your app but when i do it on my apps i have the same error