user232343
user232343

Reputation: 2118

Setting property of some pointer type

If i have property defined on this way:

@property (atomic) int prop_int;

I can set its value on this way:

[c setValue:[NSNumber numberWithInt:12345] forKey:@"prop_int"];

But if I have property which is pointer:

@property (assign) int *prop_int_ptr;

And I try to set value of this property on this way...

[c setValue:[NSValue valueWithPointer:(void*)int_ptr] forKey:@"prop_int_ptr"];

function won't work. I'm getting following error:

[<Car 0x10010a360> valueForUndefinedKey:]: this class is not key value coding-compliant for the key prop_int_ptr.'

Does anyone knows what is the way to set value of this prop_int_ptr property without setting it directly -> c.prop_int_ptr = some_int_ptr; because I'm in situation when I can't use 'hardcoded' setting of property value. I need something more generic.

Upvotes: 0

Views: 197

Answers (2)

mathieug
mathieug

Reputation: 901

You should use NSNumber* instead of int*

Upvotes: 0

Josh Hinman
Josh Hinman

Reputation: 6805

Key-value coding does not support arbitrary pointers. Does your property need to be an int pointer? If you can, declare it instead as an NSNumber:

@property (strong, nonatomic) NSNumber *prop_int

That property will be key-value compliant.

Source: http://lists.apple.com/archives/cocoa-dev/2006/May/msg00343.html

Upvotes: 2

Related Questions