• 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
CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?


  • Subject: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
  • From: Motti Shneor <email@hidden>
  • Date: Thu, 02 Jun 2011 15:01:52 +0300

Hello everyone.

We work with a CoreData model that is memory-based. However,  at times I would want to (partially) save an entity to the UserDefaults, as a dictionary.  For that, I wrote a little NSManagedObject extension (Category) with the following method:

@interface NSManagedObject (OURExtension)
@property (readonly) NSMutableDictionary *attributesAsDictionary;
@end
- (NSMutableDictionary *)attributesAsDictionary {
	NSMutableDictionary *attributesDictionary = [NSMutableDictionary dictionaryWithCapacity:[self.entity.attributesByName count]];
	for (NSAttributeDescription* attribute in self.entity.attributesByName ) {
		NSString *attribName = [attribute name];
		id attribValue = [self valueForKey:attribName];
		if (attribName && attribValue)
			[attributesDictionary setObject:attribValue forKey:attribName];
	}
	return attributesDictionary;
}

Running the method for a nice entity that I just Saved (validated) and Fetched again (to be sure it's in the store) --- the method crashes horribly on the NSString *attribName = [attribute name];

If I step inside with the debugger, I see things I can't understand.  I get into the loop, and for the first attribute ---
1. Debugger claims 'attribute's type is CFStringRef * instead of  NSAttributeDescription*
2. Summary for  attribute is "telephoneID" which is reasonable --- one of my attributes is named like that.
3. drilling down, the private "_name"  iVar for the attribute is nil but when I try to get it :
4. NSString *attribName = [attribute name] crashes and debugger looses all track of stack or anything.

I looked for "valid" "isValid" or similar properties in NSAttributeDescription and its ancestor NSPropertyDescription to no avail. Nothing in the docs will tell me WHEN is it right to use the NSAttributeDescription  in the above manner.

Ideas anyone?


Motti Shneor
---------------------------------------------------------
Ceterum censeo Microsoftinem delendam esse

_______________________________________________

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: Fwd: NSNotificationQueue Should Be Collected?
  • Next by Date: RE: What is the point of a host-reachability test that doesn't test the reachability of the host?
  • Previous by thread: Re: NSNotificationQueue Should Be Collected?
  • Next by thread: Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
  • Index(es):
    • Date
    • Thread