Skip to content

Instantly share code, notes, and snippets.

@casademora
Last active February 25, 2019 21:22
Show Gist options
  • Save casademora/753834752f3cb43b9b44 to your computer and use it in GitHub Desktop.
Save casademora/753834752f3cb43b9b44 to your computer and use it in GitHub Desktop.
Private func in swift are hidden from the ObjC runtime
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()
@merriam
Copy link

merriam commented Jan 4, 2015

@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.

@KiGi
Copy link

KiGi commented Jan 4, 2015

@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