Slide 1
Slide 1 text
Migrating from UIKit to Swi!UI efficiently
final class MyViewController: UITableViewController {
private var data = [String]()
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
let d = data[indexPath.row]
cell?.textLabel?.text = d
return cell ?? UITableViewCell()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
}
↓
struct MyView: View {
private var data = [String]()
var body: some View {
List(data, id: \.self) { d in
Text(d)
}
}
}
1