NSNumber Warning when using setter but code seems to work OK - Passing argument 1 makes integer from pointer without a cast
I have an object Foo that has an NSNumber 开发者_StackOverflow中文版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.
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 :).
Maybe the member that this property refers to has no '*' in the declaration?
EDIT:
Do you have setSiteID:
method in ".m" file?
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.
精彩评论