Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ATG

macrumors regular
Original poster
Aug 7, 2005
187
0
I'm trying to finish my second program that's not a tutorial. I'm getting some warnings that I don't understand. I wonder if you could help me. The app takes an input from a text field and outputs the factors and the prime factors into different text fields.

I have 2 arrays, facArray and pfacArray.
Here I'm trying to add integer 'x' into facArray. Whats wrong?
Code:
[facArray addObject:(@"%d", x)];
XCode says: "ACFactor.m:22: warning: passing argument 1 of 'addObject:' makes pointer from integer without a cast"

Here I'm trying to print facArray to a text box:
Code:
[factors setStringValue:(@"%@", facArray)];
XCode says: "ACFactor.m:25: warning: passing argument 1 of 'setStringValue:' from incompatible pointer type"

I have two more like that only with the other array.

Lastly I'm if the input is a prime number I have this:
Code:
[primeFactors setStringValue:(@"%d is a prime number. Please choose another number.", a)];
And this error: "ACFactor.m:47: warning: passing argument 1 of 'setStringValue:' makes pointer from integer without a cast"

Thanks for any help. :)
 

HexMonkey

Administrator emeritus
Feb 5, 2004
2,240
504
New Zealand
You can't use format strings in the way you're trying to, but you could use NSString's stringWithFormat method instead. For example:
Code:
[facArray addObject:(@"%d", x)];
would become
Code:
[facArray addObject:[NSString stringWithFormat:@"%d", x]];
 

Omen88

macrumors regular
Jan 8, 2002
177
0
Flanders (Belgium)
NSNumber

Or you could use NSNumber. e.g.:
[facArray addObject:[NSNumber numberWithInt:x]];

To get the integer value again:
[[facArray objectAtIndex:0] intValue];

You would probably use a variable for the index instead of 0.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.