Obj-C, NSScanner: nil string argument, suddenly ge

2019-09-16 02:33发布

问题:

I'm suddenly getting this warning NSScanner: nil string argument in the debug window.

I say suddenly, but I've no idea from which code has caused it.

How do I resolve this problem ?

回答1:

You check if the string is nil before creating the NSScanner with it, as you are probably creating it with

+ (id)scannerWithString:(NSString *)aString

or

- (id)initWithString:(NSString *)aString

There is no way of changing the NSScanner string, once it has been created, the compiler is just telling you that it is pointless to create a NSScanner with a nil string.



回答2:

I had solved this problem by removeObserver:forKeyPath: in dealloc where I had used KVO.