Hey,
I might be too tired to do some programing because i have worked double shift for 9 days in a row now. But its too fun to do some programming
Im new to the Backendless and i have tried to understand it, my problem is kinda simple for a normal personā¦
I have a column that i want to get data from. This column is named āKlassā, i have attached a picture where u can see it.
If I want to get only the current userās data from it and not the other users data, what do i write for code in swift?
When i write this simple code,
let backendless = Backendless.sharedInstance()
let HUser = backendless.userService.currentUser
let getInfo = HUser.getProperty(āKlassā)
print(getInfo)
It gives me obviously <null> as an answer and not 8E.
I have worked out how to log in and all that but not how to get the property of this data.
What is the difference between Asynchronous API and Synchronous API?
Thank you and have a great day!
Please try this function:
func fetchingAllUsers() {
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) -> \(user.getProperty("Klass")) ")
}
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)
}
Do you get a value of āKlassā user property?
About differences between sync and async calls:
Hi, thank you for answering!
In this bit of code i will get all the values from āKlassā, and iām only looking for the current userās āKlassā, the one that is logged in at my app.
Can i some how avoid my app to load all the users property āKlassā and only load the current userās āKlassā?
I hope you understand what i mean.
When user is logged in, you can retrieve this property:
let klass = backendless.userService.currentUser.getProperty("Klass"))
Hi,
That is my problem, when i do put that in i get <null> as an answer.
This is my result when iām running the code:
hello -> 8E
<null>
hej -> 8G
<null>
test -> 9G
<null>
user1 -> 9G
<null>
Here is my code:
func fetchingAllUsers() {
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) -> (user.getProperty(āKlassā)) ")
let klass = self.backendless.userService.currentUser.getProperty("Klass")
print(klass)
}
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)
}
So i can get the names from the backendless and the 'klass" but if i only want the loged in persons āklassā it will give me <null> as an answer.
Are you logged in before getting a currentUser property? For example:
func loginUser(email: String, password: String) {
Types.tryblock({ () -> Void in
let user = self.backendless.userService.login(email, password: password)
print("User has been logged in (SYNC): \(user.email)")
},
catchblock: { (exception) -> Void in
self.fault = exception as? Fault
print("loginUser: server reported an error: \(self.fault!))")
})
}
Try:
loginUser(email:"<user email>", password: "<user password>")
let klass = self.backendless.userService.currentUser.getProperty("Klass")
print(klass)
Now it works, thanks for the help!