Re: Core Data: Low level retrieving of data
Re: Core Data: Low level retrieving of data
- Subject: Re: Core Data: Low level retrieving of data
- From: mmalc crawford <email@hidden>
- Date: Thu, 25 Jan 2007 10:18:09 -0800
On Jan 25, 2007, at 6:07 AM, Ryan Homer wrote:
It's a lot easier to try to follow what you're doing if you use the
correct terminology.
An entity is not the same as a managed object. You typically do not
create new entities in code, you create new managed objects.
Now, I need to be able to access this data elsewhere in my code and
do other things with it (other than add/create/modify records and
store/retrieve them). To do this, and I don't know if this is the
correct way, I'm accessing the store using the code below, having
followed Apple's Low Level Core Data Tutorial.
Fetching managed objects is described here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html
>.
At first glance, it looks like you have followed the correct pattern.
If I do not create the new entity, then when I try to fetch, I'm not
able to retrieve any data from the store. I think part of the
problem (only part) is that I am not using a custom NSManagedObject
in my GUI, but when retrieving I'm trying to use the custom class in
order to use my accessors.
It's not clear what you mean here, however this is unlikely to be the
issue. Core Data *always* uses the same class to represent instances
of a given entity -- the class that you specified for the entity in
the model.
Do I need a custom NSManagedObject to read my fields (sorry, I don't
know what the correct term is but I mean my data such as name,
email, etc.)?
The correct terminology is described here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/chapter_5_section_5.html
> (note <http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdBeforeYouStart.html#//apple_ref/doc/uid/TP40004318-DontLinkElementID_13
>:
"The terminology used by Core Data is defined and explained in the
"Object Modeling" section of Cocoa Design Patterns. You should also
ensure you understand the model-view-controller design pattern, and
other related design patterns, described in the same document.").
I've tried without and I keep getting "Target does not respond to
this message selector".
Accessing properties is described here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOs.html
>
If you have a custom managed object class an you have defined suitable
accessor methods, you can invoke those. If you haven't, you use key-
value coding.
Here's what happens: if I create a new entity at the point
illustrated in the code, then when I try to fetch, my resulting
array has two objects, the new one I created and the one contact
from the store (I printed out the object in the console and I can
see all the data). If I try to access the data using my custom
NSManagedObject, I can access the first contact which was created in
memory, but trying to access the data from the second contact gives
errors (uncaught exception was raised, SIGTRAP).
My initial guess would be that you have a memory management error.
See <http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdMemory.html
> -- in particular note that the managed object context does not by
default retain fetched objects.
mmalc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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