In SwiftUI, ContentView is the main user interface, equivalent to Main ViewController in UIKit. The List command (actually a struct in SwiftUI) produces a Table on the UI.
List(model.dataTable.rows,id:\.index) { row in // this creates a Table of entries from dataTable (i.e. Terms and phrases
HStack{ // this contains formatting for the rows of the table
Text(row["Term"] as! String) // this is the Term "cell", although it's not a cell like in UIKit
Text(String(row["Phrase"] as! String)) // this is the Phrase cell, although it's not a cell like in UIKit
}
}
That's all that's needed in SwiftUI to create a working UI for your Term/Phrase data. However, in Xcode (when creating a project) you have to make sure that the Interface option for a new project specifies SwiftUI not Storyboard.
With UIKit, processing of data for a View is normally done within the ViewController of the View. With SwiftUI, the data processing is preferably done in a Data Model with results made available to SwiftUI views via (for example) the var model = DataModel.shared statement. So, for the Search Bar, the query text would be provided to the Data Model, which runs the query, then provides the result(s) back to the SwiftUI View.
If I get time later today (it's 8:30am now here in Oz) I'll extend my sample code to include searching.
Best wishes and regards, Michaela
Topic:
Programming Languages
SubTopic:
Swift
Tags: