• 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: Core Data question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data question


  • Subject: Re: Core Data question
  • From: Sandro Noel <email@hidden>
  • Date: Thu, 07 Aug 2008 14:56:44 -0400

Quincey & Marco,

Thank you guy's, Very helpful information!
:)


Sandro

On 6-Aug-08, at 3:31 PM, Sandro Noel wrote:


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

_______________________________________________

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


References: 
 >Core Data question (From: Sandro Noel <email@hidden>)

  • Prev by Date: Re: packed NSTextfield and NSFormatter in IB3 plugin...
  • Next by Date: Confusion over FSMoveObjectToTrashSync docs
  • Previous by thread: Re: Core Data question
  • Next by thread: Re: Core Data question
  • Index(es):
    • Date
    • Thread