0

I have a Question what is the different between NSSelectorFromString and Selector if i create the selector Using Selector

 let bSelector = Selector("registerRemoteNotificationWithApplication:")
 let cSelector = Selector(stringLiteral: "registerRemoteNotificationWithApplication:")

i get a warning

String literal is not a valid Objective-C selector

and when using the NSSelectorFromString

 let aSelector = NSSelectorFromString("registerRemoteNotificationWithApplication:")

there is no warning

even if the function was declared with / without @objc

  @objc func registerRemoteNotification(application:UIApplication) {


}
Bassem Tourky
  • 482
  • 5
  • 12
  • What's your question? You are just writing the fact how current Swift works. What do you want to ask? – OOPer Jul 15 '18 at 14:31
  • the compiler is giving me a warning when using Swift Selector Struct but it dose not when using Objective-c runtime NSSelectorFromString , so is there any deferent between them , should i ignore the warning or just use the NSSelectorFromString – Bassem Tourky Jul 16 '18 at 07:15
  • You should better include the question sentence into the text of your question post. – OOPer Jul 16 '18 at 07:45

1 Answers1

0

Starting with Swift 3, you should use #selector() for this. Given

class Foo: NSObject {
    @objc func registerRemoteNotification(application:UIApplication) { }
}

you would use

let selector = #selector(Foo.registerRemoteNotification(application:))
Gereon
  • 17,258
  • 4
  • 42
  • 73