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

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


  • Follow-Ups:
    • Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Code style (was: Notify With Parameters)
  • Next by Date: Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
  • Previous by thread: Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
  • Next by thread: Re: CoreData problem - AttributeDescription seems invalid --- What am I doing wrong?
  • Index(es):
    • Date
    • Thread