• 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: Custom Accessors in Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom Accessors in Core Data


  • Subject: Re: Custom Accessors in Core Data
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 2 Feb 2011 11:50:08 -0800

On Feb 2, 2011, at 09:52, Gordon Apple wrote:

> I would like to have scaler accesors and also standard (NSNumber) accessors
> in my managed objects.  The docs show some ways to handle the former, e.g.,
> "CGFloat myValue".  I prefer not to cache.  (I'm trying to retrofit an app
> to CoreData and prefer not to change all my code accesses to deal with
> NSNumber.)
>
> Assuming I do the above, but occasionally need the NSNumber, is there any
> reason why I cannot simply add a property, say "NSNumber myValuePrim" (not
> an attribute or cached value), and implement my own accessors for it, using
> the primitive value and the proper KVO?
>
> I wish CoreData had ways to automatically handle this.

What about a bit of lateral thinking? Implement the simple scalar custom accessor, and just forget about the NSNumber accessor. Instead of:

	myObject.myNumberValue

use:

	[NSNumber numberWithDouble: myObject.myValue]

in the caller. I know it seems crazy at first, to force the Core Data attribute to be converted from a NSNumber just so that you can convert it back to a NSNumber, but perhaps worrying about it comes under the heading of "premature optimization".

You do say, after all, that you need the NSNumber only "occasionally".


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Custom Accessors in Core Data
      • From: Gordon Apple <email@hidden>
References: 
 >Custom Accessors in Core Data (From: Gordon Apple <email@hidden>)

  • Prev by Date: Re: [iPhone] Is it possible to search and detect Bluetooth [MFI] headset or other [MFI] device with SDK
  • Next by Date: Re: Custom Accessors in Core Data
  • Previous by thread: Custom Accessors in Core Data
  • Next by thread: Re: Custom Accessors in Core Data
  • Index(es):
    • Date
    • Thread