Manipulate NSArray Data from Query‏

I made a query to go through the “Users” table then retrieving the data of each user. This is return in the form of an NSArray. Information included details such as their name, password & other custom relations made. My main concern in this case, is the data contained within the custom relation. Each time I post, I’m directed to the documentation on use of relations but that doesn’t seem to apply to my question, as the methods in the example do not provide a solution.

I believe my situation to be a special case. All I am requesting is that you make a similar query & guide me on how I can retrieve the information I need.

Please find the query in question below:

                let dataQuery = BackendlessDataQuery()

                let queryOptions = QueryOptions()

                queryOptions.related = ["Likes", "Likes.trackTitle"];

                dataQuery.whereClause = "name = \'\(user.name)\'"

                dataQuery.queryOptions = queryOptions

                

                let bc = self.backendless.persistenceService.find(Users.ofClass(), dataQuery:dataQuery) as BackendlessCollection

I’ve attached the output. All I want is the list of likes, as follows.

likes = (
“<Yzia.Songs: 0x7fd67a1ef470>”,
“<Yzia.Songs: 0x7fd67a1f0690>”,
“<Yzia.Songs: 0x7fd67a1f1c70>”,
“<Yzia.Songs: 0x7fd67a1f3220>”,
“<Yzia.Songs: 0x7fd67a1f4780>”,
“<Yzia.Songs: 0x7fd67a1f5f40>”,
“<Yzia.Songs: 0x7fd67a1f74e0>”,
“<Yzia.Songs: 0x7fd67a1f8a90>”,
“<Yzia.Songs: 0x7fd67a1fa070>”,
“<Yzia.Songs: 0x7fd67a1fb610>”,
“<Yzia.Songs: 0x7fd67a400c20>”,
“<Yzia.Songs: 0x7fd67a402230>”
);

Please find a screenshot of my Users table attached as well as the output when I print bc.data below.

Let’s start with things that do not look right…

    Did you create your own Users class? If so, get rid of it and use the BackendlessUser class instead. What is Likes.trackTitle? Is it also a "relation" column? If not, remove it from the "related" array in queryOptions Did you create a class for the Songs table? Does it match the schema of the Songs table?
Regards, Mark

Thanks Mark! That’s a good point, I’ll remove that queryOption & try and use the BackendlessUser class and see if that helps and yes, I my songs table matches the schema.

I tried to fiddle with this but I’m still left with a BackendLess User Object. I would like to retrieve columns from that object. Columns such as Phone, following & likes. How can I do that?

[<BackendlessUser> {

Phone = 0788480320;

"___class" = Users;

"__meta" = "{\"relationRemovalIds\":{},\"selectedProperties\":[\"password\",\"created\",\"Phone\",\"following\",\"name\",\"___class\",\"ownerId\",\"updated\",\"objectId\",\"likes\"],\"relatedObjects\":{}}";

created = "2016-02-28 16:00:32 +0000";

email = "&lt;null&gt;";

following =     (

);

lastLogin = "2016-04-02 21:29:04 +0000";

likes =     (

);

name = hillzy911;

objectId = "8E81D09B-362C-7DF3-FFFE-9AF86C56B200";

ownerId = "&lt;null&gt;";

password = "&lt;null&gt;";

updated = "2016-04-02 21:29:04 +0000";

userStatus = ENABLED;

}]

Please see the API documentation describing how to retrieve related properties:
https://backendless.com/documentation/data/ios/data_relations_retrieve.htm

thanks…all done