ios - NSNotification not working on Swift translation (from Objective-C) -
ios - NSNotification not working on Swift translation (from Objective-C) -
after converting objective-c code swift, cannot nsnotifications work. after hr of searching in web, gave up. consider next example:
func gettourl(url:string, timeoutinterval:float) -> bool { println("starting http to: \(url)") // fire notification nsnotificationcenter.defaultcenter().postnotificationname("startnotification", object: self) [...] } func getjsonfromserver() { // add together observer should fire method test when desired nsnotificationcenter.defaultcenter().addobserver(self, selector: "test:", name: "startnotification", object: self) // calls function gettourl("http://www.stackoverflow.com", timeoutinterval: 10) } func test(sender: anyobject) { println("i here!") }
i cannot find error, appreciate if else could!
the code runs, test method never called.
change in this, self nil (in order hear objects)
func getjsonfromserver() { // add together observer should fire method test when desired nsnotificationcenter.defaultcenter().addobserver(self, selector: "test:", name: "startnotification", object: nil) // calls function gettourl("http://www.stackoverflow.com", timeoutinterval: 10) }
ios objective-c swift notifications nsnotificationcenter
Comments
Post a Comment