Re: How to bind OS-X UI to display the App Bundle "CFShortVersionString" value?
Re: How to bind OS-X UI to display the App Bundle "CFShortVersionString" value?
- Subject: Re: How to bind OS-X UI to display the App Bundle "CFShortVersionString" value?
- From: Ken Thomases <email@hidden>
- Date: Sun, 21 Feb 2016 15:01:30 -0600
On Feb 21, 2016, at 2:30 PM, Motti Shneor <email@hidden> wrote:
>
> I simply want an NSTextField (Label) in one of my windows, to display the “short version string” which is in the App Bundle’s info-plist, at the “CFShortVersionString”. I hoped to do this via binding in my .xib - directly against the Application object, or any other always-available controller.
>
> Now this is NOT in the userDefaults, so I can’t bind to NSUserDefaultsController. This is also not in the NSAppliction or its delegate. I only know to retrieve this value using the NSBundle API -
>
> [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName”]
>
> but that’s hardly bind-able, and NSBundle isn’t a controller per se.
>
> I must be missing something very simple and stupid.
>
> Hint anyone?
First, bindings are not always the best approach to solve any particular problem. They can be useful, but when you run up against an area where the bindings approach seems excessively difficult, you should consider going the non-bindings route.
For example, in the view controller or window controller, you would have an outlet to the text field (say, "versionLabel"). In the controller's -viewDidLoad or -windowDidLoad method, you would simply do:
self.versionLabel.stringValue = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString”];
If you really want to use bindings, then you could create a read-only property on your view controller or window controller class. You would implement its getter to return the above value:
@property (readonly, nonatomic) NSString* mainBundleShortVersion;
- (NSString*) mainBundleShortVersion
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString”];
}
Once you've created such a property, you can bind to it.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden