• 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: Fun with Primitives
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fun with Primitives


  • Subject: Re: Fun with Primitives
  • From: Owen McKerrow <email@hidden>
  • Date: Wed, 14 Dec 2005 09:58:00 +1100

Hi Guys,

Hmmm. The specific thing Im trying to set which is causing the problem is the batchIndex of a display group.

So the call is

nextPage.takeValueForKeyPath(dictionary.objectForKey(keyName),keyName);

Where keyname is "displayGroup.currentBatchIndex" and the value is well anything. The value of the batch index is never changed, its always 1, both directly before and after the above line of code.

Any ideas ?

Owen

On 13/12/2005, at 7:39 PM, email@hidden wrote:


Owen,

Key-value coding takes care of type coercion.

takeValueForKey("myNumber", 1) may call either setMyNumber(Integer aNumber) or setMyNumber(int anInt).

Your example should work just fine with only one setter method defined.

Pierre

webobjects-dev-bounces+pierre.bernard=email@hidden wrote on 12/13/2005 06:00:49 AM:

> Hi All,
>
> I have a method that loops over a NSMutableDictionary by keyword, and
> then uses that keyword as a key value path to set the value of an
> object for another page to the value stored in the dictionary.
>
> For example we have the key value pair in the dictionary of
> "personName", "Bob".
> So I set the value in the next page with the following call
>
> nextPage.takeValueForKeyPath(dictionary.objectForKey (keyName),keyName);
>
> So in this case we set the valueForKeyPath "personName" on the next
> page to the value found in the dictionary which matches the same key,
> in this case that value would be Bob.
>
> However this breaks down when I have to deal with primitives. A
> NSMutableDictionary won't take a primitive ( e.g. an int) as a
> possible object, so we cast it to an Integer. However when you then
> try and assign this to the int on the next page it of course doesn't
> work as the int can't be assigned to an Integer.
>
> So we could check what class type we have for dictionary.objectForKey
> (keyName) and if its an Integer, use .intValue(), but that means ALL
> Integers would be cast back and this is not what we would want.
>
> Taking that one step further you can check if
> nextPage.valueForKeyPath(keyName).getClass().isInstance
> (Integer.TYPE), that is checking if you are about to set an int or
> not on the nextPage and if so cast the object to an Integer ( Integer
> value = (Integer) dictionary.objectForKey(keyName)) and then
> use .intValue() for the ones which pass this test However this also
> breaks as nextPage.takeValueForKeyPath() needs an Object not a
> primitive.
>
> I know I could just write a method that takes an Integer and assign's
> it to the int :
>
> setNumber (Integer newNum) {
> setNumber(newNum.intValue());
> }
>
> But I was hoping to make the method generic enough that it could just
> do it, otherwise I would have to write this extra method every- time I
> wanted to use it ( which may be the only way to go ).
>
> But before I headed down this path I thought I would ask and see if
> anyone has any ideas or suggestions ?
>
> Owen McKerrow
> WebMaster, emlab
> http://emlab.uow.edu.au
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - - - -
> "As of tomorrow, employees will only be able to access the building
> using individual security cards. Pictures will be taken next
> Wednesday employees will receive their cards in two weeks."
> - "Dilbert Quotes" Winner, Fred Dales, Microsoft Corp
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
email@hidden
>
> This email sent to email@hidden
>



********************************************************************** This email and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender of this message. (email@hidden) This email message has been checked for the presence of computer viruses; however this protection does not ensure this message is virus free. Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu **********************************************************************

Owen McKerrow WebMaster, emlab http://emlab.uow.edu.au

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time and still be able to function.'
-F.Scott Fitzgerald,



_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Fun with Primitives (From: email@hidden)

  • Prev by Date: stringQualifierOperators (like, contains)
  • Next by Date: SQL generation 'create index null'?
  • Previous by thread: Re: Fun with Primitives
  • Next by thread: Setting up a Target for Any Build of WOA app...
  • Index(es):
    • Date
    • Thread