PDA

View Full Version : Cocoa (too many arguments)




lostingamma
Apr 4, 2005, 06:19 PM
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:@"./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
Apr 4, 2005, 08:40 PM
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 Reader.app/Contents/Resources/%dcopy.tif", i]];

lostingamma
Apr 4, 2005, 09:22 PM
ohhh, thanks, thats just what i needed, thanks sooooo much :) :)