代码:
class CalculateElapsedTime { let uniqueId:String var startTime:NSDate var elapsedTimeInSec:Double { self.startTime = NSDate() func start() -> NSDate { } let calcTime = CalculateElapsedTime() let extraParas:Dictionary<String, AnyObject> = [ "calcTime" : calcTime, ] getUrlRespJsonDict_async(getUserIdUrl, extraParas: extraParas, respJsonDictHandler: getUserIdJsonDictHandler) func getUserIdJsonDictHandler(getJsonOk:Bool, extraParas:AnyObject?, respJsonDict:JSON) { /* decodedJsonDict=user-7aa7e3c3-bf8f-46e1-8cbe-3a5aad6e9dfb */ if extraParas != nil { if var calcTime = extraParas!["calcTime"] { calcTime = calcTime as! CalculateElapsedTime let elapsedTime = calcTime!.stop() gLog.debug("elapsedTime=\(elapsedTime)") } } |
结果出错,挂了:
2016-03-30 19:40:08.276 简道[475:53604] *** NSForwarding: warning: object 0x13671e610 of class ‘ÁÆÄÈÅì.CalculateElapsedTime’ does not implement methodSignatureForSelector: — trouble ahead Unrecognized selector -[简道.CalculateElapsedTime stop] |
搜:
NSForwarding warning of class does not implement methodSignatureForSelector trouble ahead
Does not implement methodSignatureForSelector: – trouble ahead – | Touch Code Magazine
Object X of class Y does not implement methodSignatureForSelector in Swift – Stack Overflow
去加上继承NSObject
然后就可以了:
//class CalculateElapsedTime { class CalculateElapsedTime: NSObject { let uniqueId:String var startTime:NSDate var elapsedTimeInSec:Double { self.startTime = NSDate() func start() -> NSDate { func reset(){ } func calcTimeStart(uniqueId:String){ gLog.debug("\(uniqueId)") let calcTime = CalculateElapsedTime() func calcTimeEnd(uniqueId:String){ } calcTimeStart("loginWithUserid") getUrlRespJsonDict_async(genAuthUrl, extraParas: extraParas, respJsonDictHandler: getAcessTokenHandler) } func getAcessTokenHandler(getJsonOk:Bool, extraParas:AnyObject?, respJsonDict:JSON) { /* { "data" : "2bh3ertj1a7a7jfj8hut0t3k0k", "message" : "ok", "code" : 200 } */ calcTimeEnd("loginWithUserid") |
转载请注明:在路上 » [已解决]swift出错:NSForwarding: warning of class does not implement methodSignatureForSelector trouble ahead