• 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 --- Where am I wrong?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData problem - AttributeDescription seems invalid --- Where am I wrong?


  • Subject: CoreData problem - AttributeDescription seems invalid --- Where am I wrong?
  • From: Motti Shneor <email@hidden>
  • Date: Wed, 01 Jun 2011 23:26:42 +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 this for a nice entity that I just Saved (validated) and Fetched again --- 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 type is CFStringRef * instead of  NSAttributeDescription*
2. Summary for  attribute is "telephoneID" which is reasonable --- one of my attributes is called 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

  • Follow-Ups:
    • Re: CoreData problem - AttributeDescription seems invalid --- Where am I wrong?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: How to create outlets in a cocoa category
  • Next by Date: Issue with NSRunLoop
  • Previous by thread: Re: How to create outlets in a cocoa category
  • Next by thread: Re: CoreData problem - AttributeDescription seems invalid --- Where am I wrong?
  • Index(es):
    • Date
    • Thread