On top of the original requirments, I want to compare the list of friends in user details page with the full users list so that things like greying out unregistered friends and showing the friend's details page are possible.
I've already done so before implementing Core Data, but after that I couldn't pass around the list of users to work with without first converting it from FetchedResults<CachedUser> type into [CachedUser].
To do so I imagine it to be similar as converting the user's friends NSSet to a Set<CachedFriend>, where the function will be:
func getUsersArray(_ users: FetchedResults<CachedUser>) -> [CachedUser] {
let set = users as? Set<CachedFriend> ?? [] // "users" here is the variable storing the original FetchedResults<CachedUser>
return set.sorted {
$0.wrappedName < $1.wrappedName
}
}
The question is, where should I run the function? I tried putting it inside a didSet like this:
var usersArray: [CachedUser]
@FetchRequest(sortDescriptors: [SortDescriptor(\.name)]) var users: FetchedResults<CachedUser> {
didSet {
usersArray = getUsersArray(users)
}
}
It first said "Cannot assign to property: 'self' is immutable". So I added @State to before var usersArray: [CachedUser], then another error was shown in the upper (top) level file, next to ContentView() - "Missing arguement for parameter 'usersArray' in call"
Have I been wrong since assuming the function? On the other hand how should a computed property like this be declared in general?
I hope it all makes sense. Thanks for your help.