NotificationCenter problem


#1

I’m trying really hard not to look at other solutions until I can know what is wrong with my own. I checked out the documentation for method and added (what I think) is the right code. I didn’t use an anonymous block; I used the typedef format. The program builds and compiles; the only warning I get is about an unused identifier for my block. Any insight would be appreciated.

[code]#import <Foundation/Foundation.h>
#import “BNRLogger.h”

typedef void (^NotificationBlock) (NSNotification *);

int main(int argc, const char * argv[])
{
@autoreleasepool
{

    BNRLogger *logger = [[BNRLogger alloc]init];
    
    NotificationBlock notifier;
    
    [[NSNotificationCenter defaultCenter] addObserverForName:NSCurrentLocaleDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *notifier)
    {
        NSLog(@"The system time zone has changed!");
        
    }];
    
    NSURL *url = [NSURL URLWithString:@"http://www.guttenberg.org/cache/epub/205/pg205.txt"];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    __unused NSURLConnection *fetchConn = [[NSURLConnection alloc]initWithRequest:request
                                                                         delegate:logger
                                                                 startImmediately:YES];
    
    
    __unused NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0
                                                              target:logger
                                                            selector: @selector(updateLastTime:)
                                                            userInfo:nil
                                                            repeats: YES];
            
    [[NSRunLoop currentRunLoop] run];
    
}
return 0;

}[/code]

btw, if anyone would find it convenient to chat online about these code challenges, you can reach me via Google Hangouts at jdlace@gmail.com.


#2

and the actual problem: my code doesn’t show a time zone change when I change it in sys pref.


#3

You add an observer to the Current Locale did change which is NOT the System Time Zone did change.

In the chapter 25 under global variables you will find a refresh about what is the NSLocale object.

Therefore without touching your code, in your preferences if you change the calendar from gregorian to Japanese for example, you will get you console log saying “system time zone has changed!”, that’s it.

USE AUTO COMPLETION BUT DO NOT TRUST IT!

Ciao,
Germain.