PerformSelector: withObject: but not with an object

I want to perform performSelector: withObject: but where the object is CGFloat. So this is not an item. How can i do this?

the object that I am performing the selector on is not mine; I cannot change it.

eg,

[xyz performSelector:@selector(setOffset:) withObject:2];

(after posting, I changed what I need a little:

[xyz performSelector:@selector(setOffset:) withObject:CGSizeMake(2,0)];
+1
source share
5 answers

If you are trying to call an arbitrary selector against an object that you do not have control over, you can use NSInvocation to set the selector, target and arguments and get the return value after the method is executed.

In general, however, there are simpler solutions.

+3

. - , , ( @selector (doIt:)), .

4.x, .

( , , .)

0

CGFloat. .

, , CGFloat, CGFloat typedef 'ed (float double).

, , - NSNumber.

.

0

try using IMP (a pointer to the beginning of the method implementation.)

SEL setOffsetSEL = @selector(setOffset:);
IMP setOffsetIMP = [XYZClass instanceMethodForSelector:setOffsetSEL];
setOffsetIMP(xyz, setOffsetSEL, 2);
0
source

You can use:

[NSNumber numberWithFloat:(float)value]
-2
source

All Articles