• 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: Getting A Value From An NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting A Value From An NSArray


  • Subject: Re: Getting A Value From An NSArray
  • From: Alexander Spohr <email@hidden>
  • Date: Tue, 6 Jan 2004 10:13:34 +0100

jonathan,

your array output tells you that it contains one dictionay which contains a key named "tbNavPage.tbAdminUser.tbAdminUserID". this is NOT a keyPath, it's the key itself.
it would be a path if the dictionary had a dictionary with a key "tbNavPage" which had a dictionary with a key "tbAdminUser" which had a dictionary with a key "tbAdminUserID"...


so just ask your dictionary for objectForKey("tbNavPage.tbAdminUser.tbAdminUserID").
that will give you an NSNumber of 6.


an alternative would be to use EOGenericRecord and just traversing the relationship.

	atze


Am 06.01.2004 um 09:19 schrieb Jonathan Fleming:

I've build a fetchSpec which returns several rawRow elements in the NSArray, however, if I try to get those individual values out of the array I run into these errors:


*** this is the value of the NSArray named queryResults:
({tbNavPage.tbAdminUserID = 6; tbNavPage.tbAdminUser.firstName = "Jessica"; tbNavPage.tbAdminUser.lastName = "Stanley"; tbNavPage.tbAdminUser.companyName = <com.webobjects.foundation.NSKeyValueCoding$Null>; tbNavPageID = 33; tbNavPageContentID = 18; tbNavPage.tbAdminUser.tradeStatus = "Tradesmen"; tbNavPage.tbAdminUser.tbAdminUserID = 6; })


/*------------------*/

// if I run this code I get the error below it
String _lastName = String.valueOf( ((NSDictionary)queryResults.valueForKeyPath( "tbNavPage.tbAdminUser.lastName" )).toString() );
/*
com.webobjects.foundation.NSKeyValueCoding$UnknownKeyException: valueForKey(): lookup of unknown key: 'tbAdminUser', yet the key path is in the array
*/


/*------------------*/

// if I run this code I get the result below it (this is the only one I can get a result from)
String _companyName = String.valueOf( ((NSDictionary)queryResults.objectAtIndex( 0 )).allValues().lastObject().toString() );
/*
the result produced: 6
*/


/*------------------*/

// if I run this code (trying to get lastName) I get the error below it
String _lastName = String.valueOf( ((NSDictionary)queryResults.objectAtIndex( 2 )).allValues().lastObject().toString() );
/*
Error: java.lang.IllegalArgumentException: Index (1) out of bounds [0, 0]
Reason: Index (1) out of bounds [0, 0]
*/


/*------------------*/

What's the correct way to get the value's directly from an NSArray without using a WORepition and it's index binding

Kind regards
Jonathan :^)

_________________________________________________________________
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.
_______________________________________________
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.

References: 
 >Getting A Value From An NSArray (From: "Jonathan Fleming" <email@hidden>)

  • Prev by Date: Re: TitleCasing a String - probably a java question
  • Next by Date: Re: TitleCasing a String - probably a java question
  • Previous by thread: Getting A Value From An NSArray
  • Next by thread: WebService Correct Serializing
  • Index(es):
    • Date
    • Thread