0

When I set up notification in Swift 3, I can declare the selector with or without the class prefix. In both cases, the method is an instance method. What's the difference between prefixing the class vs not? What if the selector should be pointing a class method instead?

class Test : UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    NotificationCenter.default.addObserver(self, 
        selector: #selector(fresh), name: .refresh, object: nil)
  }

  func refresh() {

  }
}

vs

class Test : UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    NotificationCenter.default.addObserver(self, 
        selector: #selector(Test.fresh), name: .refresh, object: nil)
  }

  func refresh() {

  }
}
Boon
  • 40,656
  • 60
  • 209
  • 315
  • 1
    A class method can _never_ be a Selector when the target (`self`) is an instance, so the problem doesn't arise. – matt Nov 24 '16 at 22:45
  • 3
    I explain the syntax thoroughly here: http://stackoverflow.com/a/35658335/341994 – matt Nov 24 '16 at 22:46

0 Answers0