Net bindings using structures

I have a model class for which it makes a lot of sense to have instance variables NSSize and NSPoint. It's fine.

I am trying to create an editing interface for this object. I would like to be attached to size.width and something else. This, of course, does not work.

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

+4
source share
1 answer

You do not need to create separate helpers for all participants, you can just create wrappers for types that you like, for example:

 @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 
+3
source

Source: https://habr.com/ru/post/1308612/


All Articles