What's the advantage of #selector update in Swift 2.3?

后端 未结 3 1442
孤城傲影
孤城傲影 2021-01-19 00:53

I can\'t see a problem with just writing the method name as a string. Im just curious as to why this is better?

3条回答
  •  清歌不尽
    2021-01-19 01:34

    The #selector update lets you use autocomplete. When using string literals, you could add a typo which would create a run-time error.

    Just to add, when using the migration tool in Xcode, Xcode will change your selector to something like:

    #selector(MyController.myMethod)
    

    It's acceptable to remove the class' name which makes it a little cleaner, like so:

    #selector(myMethod)
    

提交回复
热议问题