How does NSValue do its magic?

Posted by Paperflyer on Stack Overflow See other posts from Stack Overflow or by Paperflyer
Published on 2010-03-22T20:29:10Z Indexed on 2010/03/22 20:31 UTC
Read the original article Hit count: 330

I have an MVC application. The model has a property that is a struct NSSize. It is writable like this:

- (void)setSize:(NSSize)aSize;

The view sets this NSSize using key-value-coding. However, you can not key-value-code a struct, so I wrapped it in an NSValue-object like this:

[theView setValue:[NSValue valueWithSize:mySize]
           forKey:@"theModel.size"];

To my understanding, this should not work since the accessor expects a struct and not an NSValue. But it works perfectly. Magically.

How is this possible?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about key-value-coding