thomasguenzel.com

Apps/Programming

Tag: objective-c

Changing the Application Language in AppCode

When developing apps that support multiple languages I used to set the system language in the iOS Simulator settings, which required a complete reboot of the simulator. I then discovered the Application Language setting when editing build schemes in XCode under the Options tab.

Unfortunately, AppCode doesn’t have this option (or maybe I just didn’t find it). But an easy workaround is to choose Edit Configurations… in AppCode and specifying the following as Program Arguments:

-AppleLanguages (de)

where “de” specifies the language, in this case German, although “German” or “de_DE” will also work.

To easily switch between different languages, you can copy the configuration for each language and set the corresponding language code.

Automatically Update the Title of a View-Controller Based NSTabViewItem

Currently I’m working on yet another Mac app, where I have a NSTabView with multiple tabs that each represent a view controller.
I noticed that when I set my view controller’s title with

self.title = @"some other title"

nothing changes. So I wrote a small NSTabViewItem subclass that updates the title automatically by observing the title key of the view controller.

The code is on github and you can find the important part below.

@implementation GNTabViewItem

-(void)dealloc {
	[self.viewController removeObserver:self forKeyPath:@"title"];
}

-(void)setViewController:(NSViewController *)viewController {
	[self.viewController removeObserver:self forKeyPath:@"title"];
	[super setViewController:viewController];
	[self.viewController addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil];
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
	if([keyPath isEqualToString:@"title"] && object == self.viewController) {
		self.label = self.viewController.title;
		return;
	}
	[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}

@end

© 2017 thomasguenzel.com

Theme by Anders NorenUp ↑