Last active
February 25, 2019 21:22
-
-
Save casademora/753834752f3cb43b9b44 to your computer and use it in GitHub Desktop.
Private func in swift are hidden from the ObjC runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class Testing : NSObject | |
{ | |
private func privateWork() { | |
} | |
internal func internalWork(){ | |
} | |
func check(){ | |
self.respondsToSelector(Selector("privateWork")) //false | |
self.respondsToSelector(Selector("internalWork")) //true | |
} | |
} | |
let t = Testing() | |
t.check() |
@oleganza: I think Swift reserves the right to inline the private func. Much like the old JVM, it reserves the right to do lots of optimizations by enforcing rules.
@objc private func privateWork() - Now you get true//true, because it had to make a dynamically dispatched version which performSelector can see... just something to keep in mind.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@iotize in runtime all obj-c selectors are "public".
@casademora: could it be that Swift simply inlined that func, noticed it's never used anywhere and therefore created no selector for it? So some more complex private function would show up in respondsToSelector?