3

i am using core data in my application.

i am getting this error when using transformable attribute to store NSArray.

in short i want to know, what should i do to store NSArray into core data.

and how to retrive it.

this is my code.

#import <CoreData/CoreData.h>

@class category;

@interface qrandom :  NSManagedObject  
{
}

@property (nonatomic, retain) NSArray* arr;
@property (nonatomic, retain) category * cid;

@end

...........................................................................................

#import "qrandom.h"

#import "category.h"

@implementation qrandom 

@dynamic arr;
@dynamic cid;

@end

...................................................................

category.h file

#import <CoreData/CoreData.h>

@class qrandom;

@interface category :  NSManagedObject  
{
}
@property (nonatomic, retain) NSNumber * cid;
@property (nonatomic, retain) qrandom * randomrelation;

@end

....................................................................................

category.m file

#import "category.h"
#import "qrandom.h"

@implementation category

@dynamic cid;
@dynamic randomrelation;

@end

................................................................................

enter image description here

Abbas Mulani
  • 703
  • 2
  • 8
  • 19
  • Can you post the complete contents of the error message? your question really doesn't have enough information to provide a helpful answer. What doesn't a to-many relationship suffice for storing the elements of the array? – ImHuntingWabbits Jun 13 '12 at 16:10

1 Answers1

5

Basically directly storing an NSArray or an NSDictionary as a transformable attribute won't work in CoreData because it will be unable to retrieve the array's values.

See Marcus's answer which suggests just using relationships:

NSMutableArray stored with core data = WORKS, but after changing array DOESN'T WORK

BUT!

You can archive your array so that it CAN be used in your managed object. See jbrennan's response here: Saving an NSMutableArray to Core Data

Community
  • 1
  • 1
Patrick Borkowicz
  • 1,206
  • 10
  • 19