user635064 user635064 - 1 year ago 122
Objective-C Question

Cocoa bindings and macros

I have a bunch of bindings in Interface Builder. When I want to access it, I have to do this, for example:

[[NSUserDefaults standardUserDefaults] integerForKey:@"bINDDPagesTag"]

and I have to do it for other bindings at least 20, is it normal if I using
for these bindings like this:

#define kINDDPagesTag [[NSUserDefaults standardUserDefaults] integerForKey:@"bINDDPagesTag"]
#define kINDDRange [[NSUserDefaults standardUserDefaults] objectForKey:@"bINDDRange"]
#define kINDDBleedTop [[NSUserDefaults standardUserDefaults] objectForKey:@"bINDDBleedTop"]
#define kINDDBleedBottom [[NSUserDefaults standardUserDefaults] objectForKey:@"bINDDBleedBottom"]
#define kINDDBleedInside [[NSUserDefaults standardUserDefaults] objectForKey:@"bINDDBleedInside"]
#define kINDDBleedOutside [[NSUserDefaults standardUserDefaults] objectForKey:@"bINDDBleedOutside"]
#define kINDDSendData [[NSUserDefaults standardUserDefaults] objectForKey:@"bINDDSendData"]

It works perfectly, but should I use this way? I there a better way?

Answer Source

I've never done it that way, but I see no reason why your approach wouldn't work. However, I think creating a static utility class may be a bit more flexible and more maintainable, like:

@interface InterfaceConstants : NSObject {
+ (int)pagesTag;
+ (id)range;

@implementation InterfaceConstants
+ (int)pagesTag {
    return [[NSUserDefaults standardUserDefaults] integerForKey:@"bINDDPagesTag"];
+ (id)range {
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"bINDDRange"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download