Core Data question
Core Data question
- Subject: Core Data question
- From: Sandro Noel <email@hidden>
- Date: Wed, 6 Aug 2008 15:31:16 -0400
Greetings! :)
I'm experimenting with core data, bindings work just fine, I love them
and it's great and all. :)
but I want to import a massive file into the database. so I'm trying
to create it programatically.
So far I've been able to insert records in simple entities, using some
code from the Core Data Documentation.
Where my problem lies, is with relationships, and data types other
than NSString, so here comes the code.
----------------------------------------------------------------------
I have entities like this.
TransactionTypes
Atributes : Name:String
Relationships: Transaction
Transactions
Atributes: Amount:Double, Date:Date, Memo:String, Payee:String
Relationships: TransactionType
-----------------------------------------------------------------------
I retrieve/create/insert (not quite sure yet :)) an object from the
context, and set the values like this.
NSManagedObject *transaction = [NSEntityDescription
insertNewObjectForEntityForName:@"Transactions"
inManagedObjectContext:[self managedObjectContext]];
[transaction setValue:tr.transactionAmount forKey:@"Amount"];
[transaction setValue:tr.transactionType
forKey:@"TransactionType.Name"];
[transaction setValue:tr.displayName forKey:@"Name"];
[transaction setValue:tr.memo forKey:@"Memo"];
[transaction setValue:tr.datePosted forKey:@"Date"];
-----------------------------------------------------------------------
The Transaction(tr) Object Used in the code above is defined like this:
@interface OFXTransaction : NSObject {
NSString *transactionType;
NSDate *datePosted; //yyyy-mm-dd / converted from string
20080201125910
NSNumber *transactionAmount;
NSString *uniqueID;
NSString *displayName;
NSString *memo;
}
@property (readwrite, copy) NSString *transactionType;
@property (readwrite, copy) NSDate *datePosted;
@property (readwrite, copy) NSNumber *transactionAmount;
@property (readwrite, copy) NSString *uniqueID;
@property (readwrite, copy) NSString *displayName;
@property (readwrite, copy) NSString *memo;
-------------------------------------------------------------------------
Now, when I try to set the value for the [date] or [Amount] or
[TransactionType], of the ManagedObject, i get an error:
*** -[NSCFString managedObjectContext]: unrecognized selector sent to
instance 0xXXXXXeXX
The only thing that really works fine are the strings, I don't get
it... must be a simple mistake from my part here.
or something I missed in the documentation...:S
another thing I would like to understand, do relationships work like
constraints in SQL ?
in the sense that if there is no transactionType defined in the
TransactionTypes Entity,
I would not be able to insert a value in the transactionType field of
the transactions entity?
do I have to first select/fetch an object from the transactionsType
entety, and assign that to the transactionType atribute of the
transactions entety...?
Again, thank you guy's for being there, and helping out the newcomers :)
Sandro.
_______________________________________________
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