• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Key-Value Coding Limitations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Key-Value Coding Limitations


  • Subject: Re: Key-Value Coding Limitations
  • From: Mike Abdullah <email@hidden>
  • Date: Fri, 5 May 2006 17:37:54 +0100

Besides, you really ought to be using accessor methods, rather than directly editing the object in any case.

Mike.

On 5 May 2006, at 16:43PM0, James Bucanek wrote:

Jonathon Mah wrote on Saturday, May 6, 2006:

Hi all,

It seems I've come across a bug in key-value coding with direct
instance variable access. With a class such as:

File: MyClass.mm

// Objective-C++ class
@interface MyClass : NSObject
{
    NSObject *obj;
    NSRect *rectPtr;
    cppObject *cplus;
}
@end

Sending [self valueForKey:@"obj"] works as expected, but [self
valueForKey:@"rectPtr"] and @"cplus" raises an
NSUndefinedKeyException. Running class-dump shows C++ pointer objects
are converted to struct cppObject *cplus. It strikes me as strange,
since it's just another pointer; I can even change NSRect* to id, and
it will work as expected. void* raises the exception. Is this a known
limitation of struct/void pointers?

Key-value coding only works with Obj-C objects. It doesn't work with arbitrary pointers.


Key-value coding supports several "wrappers" for primitive types such as int, double, etc. This allows you set a BOOL using an NSNumber object and visa versa. But there is no inherent way of converting an arbitrary pointer to or from an Objective-C object.

If this is your class, you could create proxy accessors that get and set a Obj-C object that represents the cppObject* that you want to get or set. Once you do that, you can use key-value coding. Crudely:

- (id)cplusProxy
{
    return ([[[CppObjectProxy alloc] initWith:cplus] autorelease]);
}

- (void)setCplusProxy:(CppObjectProxy*)proxy
{
    cplus = [proxy asCppObject];
}

--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Key-Value Coding Limitations
      • From: Jonathon Mah <email@hidden>
    • Re: Key-Value Coding Limitations
      • From: Ondra Cada <email@hidden>
References: 
 >Re: Key-Value Coding Limitations (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: How to control the commit of text edit field with binding?
  • Next by Date: Notification when change of superview (addSubView:)
  • Previous by thread: Re: Key-Value Coding Limitations
  • Next by thread: Re: Key-Value Coding Limitations
  • Index(es):
    • Date
    • Thread