How to iterate in dataquery

I have a Users class where each user has a collection of music artists he/she follows from an Artist Class. Lets say I have an artist called H3nry and I want to find out which users are following H3nry I used this logic I got from this forum:

func getFollowers(followers: String)

{




    let dataQuery = BackendlessDataQuery()

    dataQuery.whereClause = "following.objectId = \'\(followers)\'"

    var error: Fault?

    let bc = backendless.data.of(BackendlessUser.ofClass()).find(dataQuery, fault: &error)

    

    if error == nil {

        print("People Who Follow:")

        print("Followers have been retrieved: \(bc.data)")

        

    }

    else {

        print("Server reported an error: \(error)")

    }

    



}

The query works 100% but it returns a whole lot of other stuff and all I want is just the users who follow H3nry. In the case below I just want that ‘User: masinh’ and I dont know how to access that from the NSObject Array. How do I get these users when the query returned gives me this output:

People Who Follow:
Followers have been retrieved: [<BackendlessUser> {
Phone = 08553;
“___class” = Users;
“__meta” = “{“relationRemovalIds”:{},“selectedProperties”:[“country”,“eventsGoing”,“created”,“ownerId”,“password”,“Phone”,“following”,“name”,”___class",“eventNotGoing”,“updated”,“objectId”,“eventsMaybe”,“likes”],“relatedObjects”:{“eventsGoing”:[“r8AF46ekNW”],“following”:[“APmGwuh34L”,“ecKLP1cYhF”,“jSBAVivc4a”],“likes”:[“a2aHY43Pap”,“A618950C-D147-4602-FFD3-366AA9924C00”,“RH4BgjEnAx”,“vSKAhUILfQ”]}}";
country = “<null>”;
created = “2016-02-28 16:16:12 +0000”;
email = “<null>”;
eventNotGoing = (
);
eventsGoing = (
“<Yzia.Shows: 0x14cff9770>”
);
eventsMaybe = (
);
following = (
“<Yzia.Artist: 0x14cffb5b0>”,
“<Yzia.Artist: 0x14e3001e0>”,
“<Yzia.Artist: 0x14e301260>”
);
lastLogin = “2016-05-02 13:56:03 +0000”;
likes = (

    "&lt;Yzia.Songs: 0x14e302860&gt;",
    "&lt;Yzia.Songs: 0x14e303de0&gt;",
    "&lt;Yzia.Songs: 0x14e305400&gt;",
    "&lt;Yzia.Songs: 0x14cff6610&gt;"
);
name = masinh;
objectId = "986D6461-07CC-02EE-FFFD-54CDD38B6800";
ownerId = "8E81D09B-362C-7DF3-FFFE-9AF86C56B200";
password = "&lt;null&gt;";
updated = "2016-05-02 13:17:05 +0000";
userStatus = ENABLED;

}]

What you get back is a collection of user objects. I didn’t understand from your question(s) what exactly you need to get, but by looking at the output, all the information is right there. Just write your code to pick whatever you need from the response…

How do I pick what I need from that? How do I go through that respnose because what i just want is the last part which shows me the user with name = masinh, who follows the queried artist.

So how do i pick that from this object?

You got an array of BackendlessUser objects. Here’s a post describing how to iterate over an array:

For each BackendlessUser object you use the following API to get a property:
https://backendless.com/documentation/users/ios/users_user_properties.htm

Thank you! It worked :slight_smile:

for object in bc.data as! [BackendlessUser]

        {

            print(object.name)

        }