4

I have a model class for which it makes quite a lot of sense to have NSSize and NSPoint instance variables. This is lovely.

I'm trying to create an editing interface for this object. I'd like to bind to size.width and whatnot. This, of course, doesn't work.

What's the cleanest, most Cocoa-y solution to this problem? Of course I could write separate accessors for the individual members of every struct I use, but it seems like there should be a better solution.

andyvn22
  • 14,696
  • 1
  • 52
  • 74

1 Answers1

3

You don't have to create seperate accessors for all the members, you could just create wrappers for the types you care about, e.g.:

@interface SizeWrapper : NSObject {
    CGFloat width, height;
}    
@property (readwrite) CGFloat width, height;    
- (id)initWithSize:(NSSize)sz;    
- (NSSize)sizeValue;
@end

@implementation SizeWrapper
@synthesize width, height;

- (id)initWithSize:(NSSize)sz {
    if (self = [super init]) {
        width  = sz.width;
        height = sz.height;
    }
    return self;
}

- (NSSize)sizeValue {
    return NSMakeSize(width, height);
}
@end
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236