Reputation: 735
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
................................................................................
Upvotes: 3
Views: 10328
Reputation: 1216
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
Upvotes: 5