views:

66

answers:

3

I have an object Foo that has an NSNumber property which is declared like this:

@property (retain) NSNumber *siteID;

and @synthesized.

When I I do something like this:

Foo *myFoo = [[Foo alloc] init];
NSNumber *newNumber = [[NSNumber alloc] initWithInt:42];
myFoo.siteID = newNumber;
[newNumber release];

The assignment on line 3 that goes through the synthesized setter appears to work just fine- myFoo.siteID has the value I'm expecting I'm able to go about my business. However, I get a warning:

Passing argument 1 of 'setSiteID: makes integer from pointer without a cast'

I'm concerned I'm doing something wrong and approaching this assignment incorrectly even though everything appears to be functioning OK.

I understand that NSNumbers are immutable and I've read some other questions about not being able to assign the value. Apologies if there is an existing topic that covers this case or if I'm just missing something basic with the property declaration.

Thanks for any tips.

A: 

Maybe the member that this property refers to has no '*' in the declaration?

EDIT:
Do you have setSiteID: method in ".m" file?

Michael Kessler
It is there see declaration below. But maybe I should have noted that this is in a UITableViewController- Not a plain vanilla NSObject. Still can't see what bearing would have on this.@interface myFoo : UITableViewController {NSNumber *siteID;}@property (retain) NSNumber *siteID;
Nick
Do you have `setSiteID:` method in ".m" file?
Michael Kessler
No there is no setSiteID: method just. I haven't overridden the synthesized setter or getter.
Nick
A: 

The error message tells you that the compiler thinks the parameter to the method -setSiteId: is an integer, not an NSNumber*. That probably means that it cannot see the declaration of the property at the point where it is using it. This, in turn, probably means you have omitted to import the header file for the Foo class.

JeremyP
It is #imported in the .m and the .h. I did check that. Thanks for these additional questions guys. I will try to isolate this out to a unit test and/or test app and see if I can repro the warning outside of the context of the full class.
Nick
+1  A: 

Really appreciate all the suggestions and followup questions. I feel like an idiot I had a typo like this where I was declaring with a different class than I was allocing with. Those classes were very similar.

oldFoo *myFoo = [[Foo alloc] init];

Typo was harder to spot with the actual very long class name - the perils of autocomplete not posting with the exact code in question and keeping old code around.

The old version of the class also had a siteID property. Things were were getting alloced with the new object and declared with the old. Again - feeling silly this morning but truly appreciate everybody's help as I tried to track this down. At least I have the good instinct to always heed warnings :).

Nick
It's really helpful to always post with code that you're sure demonstrates the problem, because very often retyping masks mistakes like this. Also, if you can't get a reduced version to show the same bug, that's often really helpful for you in figuring things out because it eliminates almost everything in your code but the actual bug.
Chuck