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

So I’m trying to get my user’s properties, such as their username and firstName. Here’s the code:


let backendless = Backendless.sharedInstance()
let query = BackendlessDataQuery()
 backendless.persistenceService.of(Users.ofClass()).find(
 query,
 response: { ( result : BackendlessCollection!) -> () in
 let users = result.getCurrentPage()
 print("loaded \(users.count) objects")
 
 for user in users as! [Users] { // error is here
 print(user.username)
 }
 
 },
 error: { ( fault : Fault!) -> () in
 print("Server reported an error: \(fault)")
 }
 )


The error I get is “NSArray element failed to match the Swift Array Element type”. I’ve tried the solutions from the other two topics but alas, here we are.

The users class:


import Foundation
class Users: NSObject {
 var username: String?
 var firstName: String?
 var email: String?
 var thumbsUp: String?
 var gender: String?
 var location: String?
 var objectId: String?
 var friends : AnyObject = []
}


Here’s the tables I have:
http://support.backendless.com/public/attachments/610b9637396244a50b63fb4f473053e2.png</img>
I’m pretty sure it’s because it’s the users table, any help is appreciated.

You don’t need to create Users class to work with Backendless app Users table, you have to use BackendlessUser class for this purpose, for example:

    func fetchingUsers() {
        
        let backendless = Backendless.sharedInstance()
        let query = BackendlessDataQuery()
        backendless.persistenceService.of(BackendlessUser.ofClass()).find(
            query,
            response: { ( result : BackendlessCollection!) -> () in
                let users = result.getCurrentPage() as! [BackendlessUser]
                print("loaded \(users.count) objects")
                for user in users  {
                    print(user.name)
                }
            },
            error: { ( fault : Fault!) -> () in
                print("Server reported an error: \(fault)")
            }
        )
    }

And you could investigate this doc, hope it will be helpful for you.