hpios
hpios copied to clipboard
What is MyObserver?
I purchased this book! Some of code in the book is really bad!
MyObserver
is an example observer here. The complete details have been omitted for brevity.
A typical key-value observer requires the object to implement the method observeValue(forKeyPath:of:change:context:)
.
Let me know how can I help.
@gvaish
Thanks for the errata. Will add these to the book.
The correct code should be:
-(id)init {
//... omitted extraneous code for brevity
//add observer
[self.reachability startNotifier];
}
//self. is optional, self.reachability ≡ reachability
-(void)networkStatusChanged:(NSNotification *)notification {
if(!reachability.isReachableViaWiFi) {
self.networkOperationQueue.suspended = YES;
[reachability stopNotifier];
} else {
self.networkOperationQueue.suspended = NO;
[reachability startNotifier];
}
}
-(void)networkStatusChanged:(NSNotification *)notification {
if(!reachability.isReachableViaWiFi) {
self.networkOperationQueue.suspended = YES;
} else {
self.networkOperationQueue.suspended = NO;
}
}
@gvaish You can not call [reachability startNotifier]
!If you call it, it would not can networkStatusChanged :
when the next time network is reachable!