我目前正在使用xCode8 beta6(swift3)中的Reachability库开发一个项目。我认为我在我的项目中正确地实现了Reachability.swift。
顺便说一句,当我调用Reachability.swift时,应用程序会崩溃在下面的reachability.startNotifier()行中。
let reachability = Reachability()!
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:",name: ReachabilityChangedNotification,object: reachability)
do{
try reachability.startNotifier()
}catch{
print("could not start reachability notifier")
}

这是我在日志里看到的。
* NSForwarding:警告:类'WebClient‘的对象0x10d939668不实现methodSignatureForSelector:-未识别的选择器+WebClient reachabilityChanged:
当然,我确实实现了reachabilityChanged选择器函数。
func reachabilityChanged(note: NSNotification) {
let reachability = note.object as! Reachability
if reachability.isReachable {
if self.pendingSurvey == true {
....
}
}
}我花了很多时间去找原因,但我想不出原因。
发布于 2016-08-24 21:22:57
在Swift 3中,func reachabilityChanged(note: NSNotification)的目标C选择器变成reachabilityChangedWithNote:.(在一些贝塔中,这可能有点不同。)因此,Reachability运行时无法找到选择器reachabilityChange:和崩溃的方法。
通常,在Swift 3中声明用于选择器reachabilityChange:的Swift方法如下:
func reachabilityChanged(_ note: NSNotification) {
//
}或者使用@objc是另一种方式:
@objc(reachabilityChange:)
func reachabilityChanged(note: NSNotification) {
//
}https://stackoverflow.com/questions/39130140
复制相似问题