• 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: Composite NSImage as Core Data transient attribute
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Composite NSImage as Core Data transient attribute


  • Subject: Re: Composite NSImage as Core Data transient attribute
  • From: Scott Stevenson <email@hidden>
  • Date: Fri, 6 Jul 2007 22:48:42 -0700


On Jun 28, 2007, at 10:12 AM, Mark Hill wrote:

I have a CoreData Entity called Composite which has a to_many relationship
with an Image Entity


Does it make sense to store the composite NSImage (re-generated each time
one of its images is updated) thus:


@interface TextureEntity : NSManagedObject {

  NSImage *compositeImage;

}

and treating it as a transient attribute in the model for KVC?

So that my NSView object's drawRect could just request
valueForKey:@"composite"

This iVar would be set during awakeFromFetch and again when its position is
updated by being dragged in the view, where I'd use something like [texture
compositeFromImages]; to rebuild and reflect those changes.


Or should I keep this View related stuff away from the Model?

The question is about overall app design, and this is only a very small snippet. It's not clear what the best thing is.


That said:

An image can be part of view, but it can also be data. It's perfectly fine for it to be part of the model class if it's real data. What you don't want is to stylistic elements specific to the application (like button images or decorations) in the model. With the example of an address book, the person's image would be part of the model.

Since you have a custom class (TextureEntity), you don't have to add "compositeImage" to the Managed Object Model if you don't want to. The cases where you need to add attribute to the Managed Object Model are:

1. You want the attribute to be saved to disk
2. You want Core Data to track changes to it (undo/redo)
3. You're using generic NSManagedObjects, rather than custom subclasses

The other side effect is that modeling an attribute may change behavior of "changed" state in a document-based app. In other words, if you update a transient attribute, the document may think it needs to be saved. This may not be what you want.

One other tip: You should just name this class "Texture" rather than "TextureEntity," and the same for the entity itself. In the case of the entity it's just redundant ("TextEntity Entity") but in the case of the NSManagedObject subclass, it's actually incorrect because it's not entity. :)

Hope that helps,

    - Scott
_______________________________________________

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


  • Prev by Date: Re: speechSynthesizer willSpeakWord trouble
  • Next by Date: Re: Adding metadata to images
  • Previous by thread: Re: NSDrawer leading offset [SOLVED]
  • Next by thread: Access Obj-C method/attribute from a C method
  • Index(es):
    • Date
    • Thread