Retrive current users column Swift

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 :slight_smile:
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!

SkaĢˆrmavbild 2016-09-13 kl. 19.49.16.png

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:"&lt;user email&gt;", password: "&lt;user password&gt;")
let klass = self.backendless.userService.currentUser.getProperty("Klass")
print(klass)

Now it works, thanks for the help!