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

xnakx

macrumors newbie
Original poster
Oct 5, 2008
17
0
Code:
thephotoQueue = [[[NSOperationQueue alloc] init] autorelease];
[thephotoQueue setMaxConcurrentOperationCount:1];
NSInteger i;
	for (i = 0; i <=kNumImages -1; i++)
	{
		NSInvocationOperation* thephotoOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadpropphotos:) object:i]; 
//Passing argument 3 of  'initwithTarget:selector:object' makes pointer from integer without cast
		NSLog(@"Queuing new thread");
		[thephotoQueue addOperation:thephotoOp];
	}
loadpropphotos takes an int as an argument. everything works fine, but i am trying to clear the warnings out before i hand it over to my testers.
How would i pass an int to the selector?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
You need to use NSNumber to pass an int. NSInvocationOperation is probably sending retain and release on the object parameter, which won't work with an int.
 

Sbrocket

macrumors 65816
Jun 3, 2007
1,250
0
/dev/null
i is not an object, which is what that warning tells you - you're attempting to make a pointer from an integer without a cast. While this will compile it will result in less than intended behavior as that method will try to deference the memory located at whatever location it is you're passing it (i=1 would mean it would deference 0x1). That means crashes.

If you can change the method, make it so that it accepts an NSNumber instead of int and pass [NSNumber numberWithInt:i] instead of just i.

Otherwise, you can take the slightly more involved route and pass along an int. You'll need to create an NSInvocation and use +[NSInvocationOperation initWithInvocation:]. You can pass along int-typed parameters with NSInvocation using -[NSInvocation setArgument:atIndex:]. Make sure to read the docs for NSInvocation - it can be tricky to use.
 

xnakx

macrumors newbie
Original poster
Oct 5, 2008
17
0
thanks for the info!
i ended up changing my function to accept a string and dealing with translations there.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.