How is this news?
How does this qualify as "Sci/Tech News for the World"? It doesn't even qualify as a particularly interesting blog post.
Much of the time, we're off exploring some framework such as GraphKit or the media browser. This time it's the turn of AppKit itself, the framework that's guaranteed to be used by every self-respecting Cocoa app. Strange as it may seem, there are plenty of undocumented goodies here, too. Let's start with localization, This is …
You can get the same thing by using the NSLocalizedStringFromTableInBundle() function, declared in Foundation. Following the example in the post, the call would look like:
NSString* cancelString = NSLocalizedStringFromTableInBundle(@"Cancel", @"Preferences", [NSBundle bundleWithIdentifier:@"com.apple.AppKit"], nil);
You can also do this same trick with any framework that has .strings resources like AppKit has, just substitute the identifier of the framework for @"com.apple.AppKit".
Thanks for that, Brian - interesting. Given the example code you provide, it's easy to see why the Apple developers came up with a more succinct way of doing things. ;-)
Incidentally, _NXKitString is just a wrapper around [NSBundle localizedStringForKey:value:table:], using another undocumented routine to retrieve the bundle instance for AppKit.
Biting the hand that feeds IT © 1998–2019