Below is the complete code the gives the error.
'''
import UIKit
class PlayersDetails {
var firstName = ""
var lastName = ""
}
class RegistrationList {
enum Status: Int,CaseIterable {
case playing, notPlaying
}
var register: [PlayersDetails] = []
private var playing: [PlayersDetails] = []
private var notPlaying: [PlayersDetails] = []
init() {
let row0Item = PlayersDetails()
row0Item.firstName = "Andy"
row0Item.lastName = "Mason"
addPlayer(row0Item, for: .notPlaying)
}
func addPlayer(_ item: PlayersDetails, for status: Status, at index: Int = -1) {
switch status {
case .playing:
if index < 0 {
playing.append(item)
} else {
playing.insert(item, at: index)
}
case .notPlaying:
if index < 0 {
notPlaying.append(item)
} else {
notPlaying.insert(item, at: index)
}
}
}
func register(for status: Status) -> [PlayersDetails] {
switch status {
case .playing:
return playing
case .notPlaying:
return notPlaying
}
}
func move(item: PlayersDetails, from sourcePriority: Status, at sourceIndex: Int, to destinationPriority: Status, at destinationIndex: Int) {
remove(item, from: sourcePriority, at: sourceIndex)
addPlayer(item, for: destinationPriority, at: destinationIndex)
}
func remove(_ item: PlayersDetails, from status: Status, at index: Int) {
switch status {
case .playing:
playing.remove(at: index)
case .notPlaying:
notPlaying.remove(at: index)
}
}
}
class RegistrationController: UIViewController {
var cellId = "cellId"
var registrationList: RegistrationList
lazy var registrationTable: UITableView = {
let table = UITableView()
table.translatesAutoresizingMaskIntoConstraints = false
table.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
return table
}()
fileprivate func setupView() {
view.addSubview(registrationTable)
registrationTable.topAnchor.constraint(equalTo: view.topAnchor, constant: 10).isActive = true
registrationTable.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
registrationTable.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
registrationTable.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
registrationTable.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
}
override func viewDidLoad() {
super.viewDidLoad()
// view.backgroundColor = .red
registrationTable.delegate = self
registrationTable.dataSource = self
setupView()
}
required init?(coder aDecoder: NSCoder) {
registrationList = RegistrationList()
super.init(coder: aDecoder)
}
}
extension RegistrationController: UITableViewDelegate, UITableViewDataSource,UISearchBarDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = registrationTable.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as UITableViewCell
cell.textLabel?.text = "hello"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
}
}
'''
In a--delegate I have added the following
""
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame:UIScreen.main.bounds)
window?.makeKeyAndVisible()
let viewController = UINavigationController(rootViewController: ViewController())
window?.rootViewController = viewController
return true
}
'''
This gives me the error.