2

I want to to run a timer to show a toast message on the view controller but I am getting error: @objc can only be used with members of classes, @objc protocols, and concrete extensions of classes

@objc protocol Test: class {
      var name: String { get }
      func showToastMessage()
 }

extension Test {
     var timer: Timer {
            return Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(showToastMessage), userInfo: nil, repeats: false)
     }

     @objc func showToastMessage() {

     }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Bharat Bhushan
  • 409
  • 4
  • 15
  • Yes Vadian, we can use the block based API of timer this is another way of implementing that but my question is why we can't define selector method in protocol extension? – Bharat Bhushan Jul 21 '18 at 07:25
  • This should help you. https://stackoverflow.com/questions/40296302/swift-3-protocol-extension-using-selector-error – Rakesha Shastri Jul 21 '18 at 07:27

0 Answers0