• 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
Using instance variable from NSArray of objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using instance variable from NSArray of objects


  • Subject: Using instance variable from NSArray of objects
  • From: Steve Gran <email@hidden>
  • Date: Fri, 9 Dec 2005 00:26:55 -0800

I'm a real Newbie so I hope I explain this well enough. I'm trying to access a variable of an array of objects and because I'm so new to programming in general (not just Cocoa) I just don't get why this is not working.

Basically I have an NSArray that (using NSArrayController and bindings) I have in a tableview. Everything works fine except when I try to access one of the variables which happens to be an integer type.

So for example, my class Cars has three instance variables (NSString carMake, NSString carModel, int priceOfCar). An NSArray myArrayOfCars holds the Cars objects (myCar1, myCar2, myCar3, etc.).

For this example let's just say the values of myCar2 are:
carMake = BMW
carModel = 530i
priceOfCar = 55000

I'd like to:

1) search through the array to find a particular carModel, then

2) return the value of priceOfCar to be used in a calculation

I was shown how (using predicates, thanks mmalc) I can filter the array as follows:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carModel like '530i'"];
theObjectINeed = [myArrayOfCars filteredArrayUsingPredicate:predicate];

And yes, sure enough, theObjectINeed is myCar2 (I can tell using NSLog). Which is great because I'm probably going to use different predicates depending on certain situations and thus won't know in advance it's myCar2 I need to find. But then when I try the following:
returnedPrice = [theObjectINeed valueForKey:@"priceOfCar"];

I don't get what I expect. And if I try to have returnedPrice sent to a NSTextView by doing the following:
[returnedPrice setIntValue: [theObjectINeed valueForKey:@"priceOfCar"]];

I get a Warning Message that says "makes integer from pointer without a cast". But the priceOfCar instance variable is an int and was declared as such. What am I doing wrong? I mainly want to be able to use that variable in some calculations so I do want it to be an integer.




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Using instance variable from NSArray of objects
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: Re: makeKeyAndOrderFront not working
  • Next by Date: Re: Using instance variable from NSArray of objects
  • Previous by thread: Re: makeKeyAndOrderFront not working
  • Next by thread: Re: Using instance variable from NSArray of objects
  • Index(es):
    • Date
    • Thread