Help with Cocoa

Discussion in 'Mac Programming' started by ATG, Aug 20, 2005.

  1. ATG macrumors regular

    Aug 7, 2005
    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?
    [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:
    [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:
    [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. :)
  2. HexMonkey Administrator


    Staff Member

    Feb 5, 2004
    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:
    [facArray addObject:(@"%d", x)];
    would become
    [facArray addObject:[NSString stringWithFormat:@"%d", x]];
  3. Omen88 macrumors regular


    Jan 8, 2002
    Flanders (Belgium)

    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.

Share This Page