• 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: How do I do KVC/KVO for struct properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I do KVC/KVO for struct properties


  • Subject: Re: How do I do KVC/KVO for struct properties
  • From: "Greg Herlihy" <email@hidden>
  • Date: Thu, 16 Mar 2006 17:14:57 -0800

Overriding either valueForKey: or setValue:forKey: is very much a bad idea. You should review the Core Data Programming guide:

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/index.html

especially the "non-standard attributes" section for the proper procedure. Essentially you should create a transient attribute for the struct property, assign it an "undefined type" and then use an NSValue object to wrap the struct so that it can be stored as an object. And yes, a custom accessor routine does need to manually send change noftifications whenever reading or writing an attribute of a managed object.

Greg

----- Original Message ----- From: "Derrick Bass" <email@hidden>
To: <email@hidden>
Sent: Thursday, March 16, 2006 4:32 PM
Subject: How do I do KVC/KVO for struct properties



I'd like to support KVC for a struct (QTTime, to be specific) property of a class. I added a valueForKey: and setValueForKey: pair of methods. When they get the "time" key, they pack/unpack the QTTime from an NSValue; otherwise they call super's implementation. I also made value transformer so the table in my view can convert between strings and NSValue's containing QTTimes. That all seems to work wonderfully.

The problem is that now I'm trying to do some KVO stuff and I've discovered that notifications are not sent for changes the "time" key. Do I have to manually send these notifications in my overridden valueForKey: method? Or is overriding valueForKey: not the right way to support structs in the first place?

Thanks in advance for any help.

Derrick

_______________________________________________
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

_______________________________________________ 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
References: 
 >How do I do KVC/KVO for struct properties (From: Derrick Bass <email@hidden>)

  • Prev by Date: Crash in removeObserver
  • Next by Date: Startup Code
  • Previous by thread: How do I do KVC/KVO for struct properties
  • Next by thread: Re: How do I do KVC/KVO for struct properties
  • Index(es):
    • Date
    • Thread