I'm following this tutorial on creating a collapsible TableView:
https://www.youtube.com/watch?v=Q8k9E1gQ_qg
He's loading a String array of names into the tableview like so:
struct ExpandableNames {
var isExpanded: Bool
let names: [String]
}
var twoDimensionalArray = [
ExpandableNames(isExpanded: true, names: ["Amy", "Bill", "Zack", "Steve", "Jack", "Jill", "Mary"]),
ExpandableNames(isExpanded: true, names: ["Carl", "Chris", "Christina", "Cameron"]),
ExpandableNames(isExpanded: true, names: ["David", "Dan"]),
ExpandableNames(isExpanded: true, names: ["Patrick", "Patty"]),
]
I would instead like to create the String array of names from my Codable User model's "name" variable:
struct User: Codable {
//var id: Int
var user_id: Int
var name: String
static func endpointForUsers() -> String {
return "users.php"
}
}
EDIT: In short... I have a [User] and I want a [String] made up of the name properties from the [User] array.
Could you please explain how I can then load all the names from my User codable as a String array? (Like the one in the tutorial.)
Thanks in advance!
[User]and you want[String]made up just of thenameproperties from the[User]array?map? What exactly is the hard part here? — And why does it matter that User is Codable?namesList = usersList.map(\.name)