Security Type Selector in Swift 2.0

Since previous answers were polluted with older versions of Swift and unrelated answers, I will try to ask this question more precisely:

Does Swift 2.0 have a type selector or a way at compile time to create a selector from a function, not a string?

If the answer is no, please provide documentation for the answer. If yes, provide an example.

I know about closures, however, using closures is not an option for the Cocoa API with Objective-C compatibility.

func init()
{
     someCall("quit") // not type-safe
     someCall(quit) // type-safe, syntax not supported in Swift
     // [someCall: @selector(quit)]; // supported objective-c syntax
}

func someCall(selector : Selector) { ...}
func quit() { ...}
+4
source share

Source: https://habr.com/ru/post/1598625/


All Articles