Reputation: 569
This may probably basic question but I'm not sure how to proceed
I have an object from struct
struct EmployeeInfo {
let name: String
let city: String
let phone: [Phone]
let email: String
}
struct Phone {
let direct: String?
let cell: String?
let home: String?
}
Phone struct has optional values
In table view I want to display Name, Phone, Email, City in this order
My Question is Do I have to manually parse this to array with the order I want and then populate UI?
I could do if i use static UI, but I want this to be in tableview for other reasons.
Please advice
Upvotes: 0
Views: 45
Reputation: 318854
When implementing a table view you implement the various UITableViewDataSource
(and UITableViewDelegate
) methods to populate your table view. Normally the data source methods base their responses on some data structure you have.
So yes, you should create an array that contains the data you want to show in the table so the data source methods can access that data.
If the table view can be sorted and/or filtered or if it can be searched then you want a separate array from your original data. You build the new array from the original data based on how the data should be sorted and/or filtered. This keeps the original data intact and allows the data source methods to access just the data needed to be displayed.
Upvotes: 1