Error Retrieving Data All of a sudden

I’m having trouble retrieving a user’s properties, the code was working fine this morning and is now crashing without me changing anything.
Here’s the code:


func getCurrentUserProperties() {
 
 ProgressHUD.show("Loading data...")
 
 let whereClause = "objectId = '\(currentUser.objectId)'"
 print(currentUser)
 print(whereClause)
 let dataQuery = BackendlessDataQuery()
 let dataStore = backendless.persistenceService.of(BackendlessUser.ofClass())
 
 dataQuery.whereClause = whereClause
 
 dataStore.find(dataQuery, response: { (user : BackendlessCollection!) in
 for user in user.data as! [BackendlessUser] {
 //Users properties
 let firstName = user.getProperty("firstName") as! String
 let username = user.getProperty("username") as! String
 let gender = user.getProperty("gender") as! String
 let location = user.getProperty("location") as! String
 let thumbsUp = user.getProperty("thumbsUp") as! String
 let friends = user.getProperty("friends").count().description
 let age = user.getProperty("age") as AnyObject
 
 currentUserProperties.setValuesForKeysWithDictionary(["firstName": firstName, "username": username, "gender": gender, "location": location, "thumbsUp" : thumbsUp, "friends" : friends, "age" : age])
 
 if friendUsernamesArray.count > 0 {
 friendUsernamesArray.removeAll()
 friendLocationsArray.removeAll()
 friendObjectIdsArray.removeAll()
 friendsArray.removeAll()
 }
 
 //User's friends
 let userFriends = user.getProperty("friends")
 
 //friendsArray = userFriends.data as! [BackendlessUser]
 
 for friend in userFriends as! [BackendlessUser]{
 
 friendsArray.append(friend)
 
 friendCount.advancedBy(1)
 
 let username = friend.getProperty("username") as! String
 let location = friend.getProperty("location") as! String
 let objectId = friend.objectId
 let profilePicture = friend.getProperty("profilePicture") as! String
 
 friendUsernamesArray.append(username)
 friendLocationsArray.append(location)
 friendObjectIdsArray.append(objectId)
 friendProfilePicturesArray.append(profilePicture)
 }
 
 ProgressHUD.dismiss()
 ProgressHUD.showSuccess("Data Loaded")
 
 }
 }) { (fault : Fault!) in
 ProgressHUD.dismiss()
 ProgressHUD.showError(fault.detail)
 print("error fetching currentUserProperties : \(fault)")
 }
}

Thanks guys.

Hi again Mudasan,

What error message do you receive?

Just a lldb error, it crashes on the line:

for user in user.data as! [BackendlessUser] {

I’m not too sure how to debug this, any help is appreciated.

What type should your “user” variable have here?

A backendless user? So I can retrieve its properties and whatnot

But you already have this variable as BackendlessCollection (you receive it in response). Try using different names for the element and for the whole collection.

I changed both the variables, but still getting a crash, it was working this morning so I’m not sure what’s gone wrong.

dataStore.find(dataQuery, response: { (returnedUser : BackendlessCollection!) in




            for test in returnedUser.data as! [BackendlessUser] { //error here

I changed the response to returnedUser and the user to test. No luck

Do you now receive exactly the same error? Note that you should have renamed them not only in this line, but further, too.

I renamed all references to the variables in that function so that’s not the problem, and yeah, same error.

I checked a backup of my project, which was from a few days ago and it isn’t working either. Maybe I did something to my backend, but I’ve got no idea what. Help guys

Okay so I fixed it, when the backendless servers were having issues, I troubleshooted by deleting all my user properties and creating them again. Turns out I had a property named something else in the database and something else in the code, so the code was trying to retrieve a property that didn’t exist.