Mac Cocoa (too many arguments)

lostingamma

macrumors member
Original poster
Apr 4, 2005
32
0
when i try this code in cocoa, i get an error that says too many arguemnts, however, its only one arugment, heres the code:

NSImage *tmpImage;
tmpImage = [[NSImage alloc] init];
[tmpImage initWithContentsOfFile:mad:"./Mind Reader.app/Contents/Resources/%dcopy.tif", i];
the code works fine if instead of using an arguemnt, i completely define the path to the image, but then, i would have to define like 25 images serperatly. and don't worry about what i is set to, thats all taken care of, its just that i keep getting this: "too many arguments to function", when its only 1 argument :(
 

HexMonkey

Administrator
Staff member
Feb 5, 2004
2,161
433
New Zealand
The problem is that format strings (those containing format specifiers such as %d) are only supported by a few methods. Luckily there's an easy workaround, using NSString's stringWithFormat, as follows:

Code:
NSImage *tmpImage;
tmpImage = [[NSImage alloc] init];
[tmpImage initWithContentsOfFile:[NSString stringWithFormat:@"./Mind Reader.app/Contents/Resources/%dcopy.tif", i]];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.