views:

64

answers:

1

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.

+3  A: 

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
Georg Fritzsche
This is interesting, but I'm not sure how to apply it to binding a text field. Wouldn't I still need to write accessors?
andyvn22
@andyvn22: Removed that part as there would be still some work left.
Georg Fritzsche
This still upsets me (why have CGFloat then!?) but I suppose it will do.
andyvn22