1

I am currently developing a project using Reachability library in xCode8 beta6(swift3). I think I correctly implemented Reachability.swift into my project.

By the way, the app crashes in the following line of Reachability.swift when I call 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")
    }

enter image description here Here is what I can see in the log.

*** NSForwarding: warning: object 0x10d939668 of class 'WebClient' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector +[WebClient reachabilityChanged:]

Of course, I did implemented reachabilityChanged selector function.

func reachabilityChanged(note: NSNotification) {

        let reachability = note.object as! Reachability

        if reachability.isReachable {
            if self.pendingSurvey == true {
               ....
            }
        }
    }

I am spending much time to find the reason but I can not figure it out.

nine9stars
  • 247
  • 3
  • 12

1 Answers1

0

In Swift 3, Objective-C selector for func reachabilityChanged(note: NSNotification) becomes reachabilityChangedWithNote:. (This may be a little bit different in some betas.) So, the Reachability runtime cannot find the method for selector reachabilityChange: and crashes.

Usually you declare a Swift method for selector reachabilityChange: in Swift 3 as:

func reachabilityChanged(_ note: NSNotification) {
    //
}

Or using @objc is another way:

@objc(reachabilityChange:)
func reachabilityChanged(note: NSNotification) {
    //
}
OOPer
  • 47,149
  • 6
  • 107
  • 142