• 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: initiate content of NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initiate content of NSArray


  • Subject: Re: initiate content of NSArray
  • From: "Jonathan Fleming" <email@hidden>
  • Date: Wed, 23 Jun 2004 03:27:41 +0100

Hi Goh,

I think this will help you, it's an post I kept from Jonathan Rochkind:

From:
Jonathan Rochkind <email@hidden>
Re: updating multiple objects at once
Date:
Mon, 15 Sep 2003 13:33:07 -0500

No matter what, multiple update statements will be sent to the db. But, they will be sent in one transaction when you call saveChanges().

It's a little known fact about NSArray, that it implements takeValueForKey to call the same named method with the same arguments on each of the elements of the array. And takeValueForKey on an EO will call the single-argument method with the name 'key'.

So you should be able to do something like:

fetchedObjects.takeValueForKey( new Boolean(false), "someBooleanAttribute");

to set "someBooleanAttribute" to false on all the objects. You will still need to call editingContext.saveChanges() to commit those changes to the db.

This saves just two or three lines of code from iterating though things by hand. The compiled code is no more efficient whatsoever then just looping through things by hand. Personally, I'd just loop through things by hand, to make the code more clear (to someone who is confused by the takeValueForKey call), and to avoid putting a method name in a String literal---if you ever change the name of someBooleanAttribute, the takeValueForKey call will still compile, but will product a runtime exception.

HTH
Jonathan F :^)


From: Goh Keng Boon <email@hidden>
To: wojingo <email@hidden>
CC: WebObjects Developer <email@hidden>
Subject: Re: initiate content of NSArray
Date: Wed, 23 Jun 2004 09:48:56 +0800

Hi can you explain in detail how to do that?

I've already fetch all content into an NSArray and bind this array to List of WORepetition, i need to set value for one of the attribute inside that NSArray(for every record),
so i'm not sure how to set that? Am i going to loop through the NSArray to set them record by record?


KB

On 22-Jun-04, at 11:52 PM, wojingo wrote:

Hi,

I think you could use awakeFromFetch(called for you when fetched from
DB:) and awakeFromInsertion (called for you when its inserted into an
editingContext).

HTH.

regards
-
shaun


On Tue, 2004-06-22 at 21:36, Goh Keng Boon wrote:
Hi,

I got this EO called "Invoice" and it has a to many relationship with
"InvoiceItem"

By using "Invoice", i'm able to display all then content and put
Invoice.relationwithinvoiceitem in the List of WORepetition
as well as anInvoiceItem in the item of WORepetition

I would like to set some value to every anInvoiceItem, so that after it
listed by the WORepetition, there will have some default
values there, may i know how can i do that? Thanks


KB
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.



_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.



  • Prev by Date: ".jar" Plugins to a WebObjects application?
  • Next by Date: Re: ".jar" Plugins to a WebObjects application?
  • Previous by thread: Re: initiate content of NSArray
  • Next by thread: Duplicate records
  • Index(es):
    • Date
    • Thread