2
votes

For some reason this has just started happening. The only thing I did today was add the launch images.

I am getting this error:

2017-09-14 03:51:59.110379 GameTest[2671:668473] -[NSConcreteNotification length]: unrecognized selector sent to instance 0x1702503b0
2017-09-14 03:51:59.134158 GameTest[2671:668473] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteNotification length]: unrecognized selector sent to instance 0x1702503b0'
*** First throw call stack:
(0x1895581c0 0x187f9055c 0x18955f278 0x18955c278 0x18945659c 0x1010327ac 0x100ff8738 0x10145dcf8 0x1000711d0 0x1894f222c 0x1894f1930 0x1894f16ac 0x189560b9c 0x189433bf4 0x189f396bc 0x1000756f8 0x10004bc3c 0x10175525c 0x10175521c 0x10175a284 0x189505f2c 0x189503b18 0x189432048 0x18aeb3198 0x18f395bd0 0x18f390908 0x100078d68 0x1884145b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

In my app delegate I have this code from

reachability.whenReachable = { reachability in
    // this is called on a background thread, but UI updates must
    // be on the main thread, like this:
    DispatchQueue.main.async {
        if reachability.isReachableViaWiFi {
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "hasInternet"), object: nil)
        } else {
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "hasInternet"), object: nil)
        }
    }
}
reachability.whenUnreachable = { reachability in
    // this is called on a background thread, but UI updates must
    // be on the main thread, like this:
    DispatchQueue.main.async {
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "noInternet"), object: nil)
    }
}

The error seems to be this line:

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "noInternet"), object: nil)

enter image description here

Can someone help me fix this? The other questions do not seem to be related to notifications and I am not finding them useful.

2
Can you post the code of the things that observe the noInternet notification? My inclination is that the selector you pass to that method may be incorrect. - Fred Faust
I'm having this same issue (crash on calling post). Seems crazy to me since this is so basic and I've used NotificationCenter so many times before. - Brian Sachetta

2 Answers

1
votes

Check the parameter type of the selector you are passing to NotificationCenter.addObserver(_:selector:name:object). The selector must have one and only one argument, an instance of Notification.

I suspect you are calling (either directly or indirectly) length on the object being passed in to your selector. That is not defined on the Notification type, hence the exception.

0
votes

Check your selector names where you listen to notifications, maybe missing ':' at the end to receive notification parameter