swift - NSTimer does not invoke a private func as selector -


i working on gist: pasteboardwatcher.swift in invoked nstimer object this:

func startpolling () {         // setup , start of timer         timer = nstimer.scheduledtimerwithtimeinterval(2, target: self, selector: selector("checkforchangesinpasteboard"), userinfo: nil, repeats: true) } 

where definition of checkforchangesinpasteboard function is:

func checkforchangesinpasteboard() {         // definition continues.. } 

i don't want expose function checkforchangesinpasteboard other classes, therefore want mark private reason when so, throws below exception:

-[pasteboardwatcher.pasteboardwatcher checkforchangesinpasteboard]: unrecognized selector sent instance 

if don't mark private works perfectly.

is there way can keep method private, hiding other classes?

according using swift cocoa , objective-c:

“ declarations marked private modifier not appear in generated header. private declarations not exposed objective-c unless explicitly marked @ibaction, @iboutlet, or @objc well.”

excerpt from: apple inc. “using swift cocoa , objective-c (swift 2 prerelease).” ibooks. https://itun.es/us/uttw7.l

so, can mark function @objc desired behavior. tested in 1 of apps had used public visibility because assumed objective-c couldn't see private declarations @ all, , works when marked private , decorated @objc.


i saw related question: swift access control target selectors — same thing think yours phrased in more general way not strictly duplicate.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -