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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]