Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
- Subject: Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
- From: Steve Steinitz <email@hidden>
- Date: Fri, 03 Jun 2011 09:17:36 +1000
Hi Matti,
On 2/06/11, Motti Shneor <email@hidden> wrote:
@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;
}
I recall having some problems looping over attributes too. Here
is some working code which solves the (known) problem that Xcode
4 no longer leaves uninitialized integer attributes as nil:
NSEntityDescription * anEntity = self.entity;
// 22 Mar 11 - brute force work around for Xcode 4's
setting of numbers to zero.
for (NSPropertyDescription * property in anEntity)
{
if ([property isKindOfClass: [NSAttributeDescription class]])
{
NSAttributeDescription * attribute =
(NSAttributeDescription *) property;
NSAttributeType anAttributeType = [attribute attributeType];
if ( NSInteger16AttributeType ==
anAttributeType ||
NSFloatAttributeType ==
anAttributeType ||
NSInteger32AttributeType ==
anAttributeType ||
NSInteger64AttributeType ==
anAttributeType ||
NSDecimalAttributeType ==
anAttributeType ||
NSDoubleAttributeType == anAttributeType
)
{
[self setValue: nil forKey: attribute.name];
}
}
}
Notice how I had to loop on NSPropertyDescription rather than
NSAttributeDescription. Perhaps that will help you?
Cheers,
Steve
_______________________________________________
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