Hey, I’ve created a one-to-many relations column in the default Users table named friends… When using the application and adding a friend from it, I can successfully retrieve the friend/s but when trying to retrieve and access the friend/s after closing the app or adding the friends using backendless data viewer… It fails giving"NSARRAY ELEMENT FAILED TO MATCH THE SWIFT ARRAY ELEMENT TYPE" the code where the retrieval occurs is
users = currentUser.getProperty("friends") as! [BackendlessUser]
print(users) // Error occurs here
Thank you in advance 
Hi, Moussa.
Please, could you try to investigate documentation about work with relations.
https://backendless.com/documentation/data/ios/data_relations_retrieve.htm
p.s. what do you mean when say “retrieve and access the friend/s after closing the app”.
Hello,
I’ve taken a look in the documentation and couldn’t work it out much so I used the code above to do the retrieval… Oh that was a bit confusing I’m sorry, I meant after relaunching the app, when I try to retrieve the users I get the error mentioned above…
Thank you 
Update: I’ve decided to give the code in the documentations a try and then I remembered what I wasn’t being able to figure out… When retrieving the users in the relation, all the users are being retrieved instead of the ones that are actually in the relation…
let whereClause = "objectId = '\(currentUser.objectId)'"
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
let dataStore = backendless.persistenceService.of(BackendlessUser.ofClass())
dataStore.find(dataQuery, response: { (user:BackendlessCollection!) -> Void in
let currentArray = user.getCurrentPage() as Array
self.me = currentArray[0] as! BackendlessUser
let whereClause = "objectId != '\(self.currentUser.objectId)'"
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
let queryOptions = QueryOptions()
queryOptions.related = ["friends"];
dataQuery.queryOptions = queryOptions
var error: Fault?
let bc = backendless.data.of(self.me.ofClass()).find(dataQuery, fault: &error)
if error == nil {
print("Friends have been retrieved: \(bc.data)")
}
else {
print("Server reported an error: \(error)")
}
}) { (fault: Fault!) -> Void in
print("error, couldnt get user avatar: \(fault)")
}
I’m using the code above
Thank you for your time 
Moussa, please, clarify: now do it work for you?
If not, than provide your appId here or to support@backendless.com, we will investigate this issue with your data.
It didn’t work, I’ll be providing my app id with a link to the question right now…
Thank you 
The email was sent, my problem is that the code is retrieving all users in the Users table instead of the ones that are actually in the relation named “friends”
Thank you in advance 
Hi Moussa,
Let investigate your sample code.
In the first part of it you have got your current user:
let whereClause = "objectId = '\(currentUser.objectId)'"
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
let dataStore = backendless.persistenceService.of(BackendlessUser.ofClass())
dataStore.find(dataQuery, response: { (user:BackendlessCollection!) -> Void in
let currentArray = user.getCurrentPage() as Array
self.me = currentArray[0] as! BackendlessUser
Why? You already have currentUser!
Then you have got all users instead current user (with loading “friends” one-to-many relation):
let whereClause = "objectId != '\(self.currentUser.objectId)'"
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
let queryOptions = QueryOptions()
queryOptions.related = ["friends"];
dataQuery.queryOptions = queryOptions
var error: Fault?
let bc = backendless.data.of(self.me.ofClass()).find(dataQuery, fault: &error)
if error == nil {
print("Friends have been retrieved: \(bc.data)")
}
else {
print("Server reported an error: \(error)")
}
}) { (fault: Fault!) -> Void in
print("error, couldn't get user avatar: \(fault)")
}
And yes, In line 10 bc.data contains all users instead current user - associated with your code.
Regards,
Slava
The simplest way to retrieve friends of current user is, for example:
func retrieveCurrentUserFriends() {
Types.tryblock({ () -> Void in
let currentUser = self.backendless.userService.currentUser
print("Current user: \(currentUser)")
self.backendless.data.of(BackendlessUser.ofClass()).load(currentUser, relations: ["friends"])
let friends = currentUser.getProperty("friends") as! [BackendlessUser]
print("Friends: \(friends)")
},
catchblock: { (exception) -> Void in
print("retrieveCurrentUserFriends - Server reported an error: \(exception as! Fault)")
}
)
}
Thank you for the amazing support! I really don’t know what came to my head when I retrieved the currentUser when I already actually had the currentUser(totally blacked out I guess)
Again, thank you for the example, that helped a lot and again thank you loads!