So I have a network controller class that is of the type NSObject and with in it I have a protocol for delegate:
protocol NetworkControllerDelegate: class {
func stateChanged(_ state: NetworkState)
func setNotInMatch()
func player(_ playerIndex: UInt8, movedToPosX posX: Int)
func matchStarted(_ match: Match)
}
and I have a ViewController of type UIViewController that tries to receive the delegate updates but its not working. In my network controller I set:
var delegate: NetworkControllerDelegate?
and I also trigger the delegate function
delegate?.matchStarted(match!)
in the UIViewController I conform to delegate and listen but nothing happens
class ConnectPlayerViewController: UIViewController, NetworkControllerDelegate {
func stateChanged(_ state: NetworkState) {
print("stateChanged")
}
func setNotInMatch() {
print("sentNotInMatch")
}
func player(_ playerIndex: UInt8, movedToPosX posX: Int) {
print("recieved Player Update")
}
let networkhandler = NetWorkController()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func ConnectUser(_ sender: UIButton) {
networkhandler.connect()
}
func matchStarted(_ match: Match) {
print(match)
}
}
the networkhandler.connect() just calls a function in the network controller that in the end triggers the delegate, the delegate is triggered but its not being received in my UIViewController, I've read online but they all seem to be from UIViewController to UIViewController. However I'm not navigation between views but instead calling a NSObject class that should trigger the delegate.