I am a very green nubie, anyways, I am working through a tutorial that walks me through using the NSLocale class to get the local currency, like this:
NSLocale *here = [NSLocale currentLocale];
NSString *currency = [here objectForKey:NSLocaleCountryCode];
NSLog(@"Money is %@", currency);
So, I understand that I am creating an instance of the NSLocale class called 'here', then I send the 'here' object a message asking for the objectForKey, and the result is returned into the NSString, called 'currency'. Last, I print the currency value with the NSLog.
Ok, so here's my question, I then reviewed what other methods are on the NSLocale class and I found one called 'preferredLanguages', it returns an array of the preferred languages. So I though I would call that method and then print it to the log, just for grins and to help me learn. Going off of the example above, I figured I would call it like this. Starting with the fact that I already have an instance of the NSLocale class called 'here' from the code above, I thought that I would just need the following ( I am repeating the three lines above just so it is easy to read here. )
NSLocale *here = [NSLocale currentLocale];
NSString *currency = [here objectForKey:NSLocaleCountryCode];
NSLog(@"Money is %@", currency);
NSArray *prefLangs = [here preferredLanguages];
NSLog(@"Preferred Languages are: %@", prefLangs);
But that didn't work, I got an error message that said, "No visible @interface for 'NSLocale' declares the selector 'preferredLanguages'
I figured out that I must do it this way instead:
NSLocale *here = [NSLocale currentLocale];
NSString *currency = [here objectForKey:NSLocaleCountryCode];
NSLog(@"Money is %@", currency);
NSArray *prefLangs = [NSLocale preferredLanguages];
NSLog(@"Preferred Languages are: %@", prefLangs);
I just don't understand why I had to call the method like this: [NSLocale preferredLanguages], instead of [here preferredLanguages]. The instance of 'here' is already created above. Can someone please explain.