Mac Cocoa (too many arguments)


macrumors member
Original poster
Apr 4, 2005
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", 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 :(


Staff member
Feb 5, 2004
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:

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