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.