Nested function selector in swift for testing -


here situation , perhaps there easier way this:

i'm testing stuff uses notifications , didn't want have define expectations class level optional variables wondering if can make them local variables function in such way notification handler can access them.

my attempt make notification handler functions nested functions inside top level test function - i've run selector naming issues i'm not sure need tell notification handler call

class fileplayertests: xctestcase {  func testfileplayback() {       let f1url : nsurl = nsbundle(forclass: fileplayertests.self).urlforresource("test1", withextension: "csv")!     let f2url : nsurl = nsbundle(forclass: fileplayertests.self).urlforresource("test2", withextension: "csv")!     let f3url : nsurl = nsbundle(forclass: fileplayertests.self).urlforresource("test3", withextension: "csv")!      let f1 = dm.createfileplayerfromurl(f1url)     let f2 = dm.createfileplayerfromurl(f2url)     let f3 = dm.createfileplayerfromurl(f3url)       let e1 = expectationwithdescription("xplane1")     let e2 = expectationwithdescription("xplane2")     let e3 = expectationwithdescription("xplane3")        f1?.startplayback()       //define locationmessage observer     nc.addobserver(self, selector: "newhandler:",         name: dmnotification.locationdata.rawvalue,         object: nil)       ///prints out new location message     func newhandler(notif: nsnotification) {         let msg = notif.aslocationmessage!         println(msg)          e1.fulfill()     }  } } 

so code crashing because can't find selector.

1) valid?

2) how name selector correctly found?

the problem saying this:

nc.addobserver(self, selector: "newhandler:" ... 

but self, fileplayertests class, has no selector called newhandler: - because have defined function local function inside testfileplayback function. exists locally - in eyes of code runs after inside testfileplayback function - , temporarily, i.e. while testfileplayback running.

you must define newhandler: @ top level of fileplayertests class method notification center can call.

that may (i.e. will) mean have promote other stuff in method top level well, of course.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -