Results for performSelector: differ from standard dot notation call?

Results for performSelector: differ from standard dot notation call?

I was very puzzled by some unexpected compile errors in my code recently. I did some troubleshooting, and I came up with this bit of test code:

1 float performSelectorResult, messageResult; 2 SEL selector = @selector(smallContentCellMargin); 3 4 NSLog (@"selector %s result %f", selector,  [defaults performSelector:selector]); 5 NSLog (@"message result is %f", defaults.smallContentCellMargin); 6 7 performSelectorResult = [defaults performSelector:selector]; 8 messageResult = defaults.smallContentCellMargin; 

If I run the code as-is, I get a compile error on line 7: "incompatible types in assignment". However, if I comment out line 7 the code build and runs; the results in NSLog are:

2009-07-21 18:31:44.823 ICE[24347:20b] selector smallContentCellMargin result 0.000000 2009-07-21 18:31:44.830 ICE[24347:20b] message result is 7.000000 

I've used very similar code to retrieve a UIFont, but never a float. Is there something I don't know, or is this a bug in Objective-C? I'm very confused.

How to intercept text from the keyboard and format it before it show in the cell?


Getting an iPhone app's product name at runtime?
First, this you are treating a selector as a string when logging with NSLog. declaring global variables in iPhone projectDon't did this - a SEL is not a string. Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary?Use the %@ format and NSStringFromSelector(aSelector).. Why is my UIImageView blurred? For the issue at hand, -performSelector: is defined to job with any selector this has an object return type. SHowing Activity Indicator View Using Thread Shows This Error in gdb?Due to the ABI, you must receive away with using this for int return types up to the size of a pointer (depending upon runtime implementation details), although you generally cannot receive away with it for float return values, as you've noticed.. Unable to push notifications to iPhone in .NET - .PEM certificate problem? For non-object return values, you should use NSInvocation, or -valueForKey:. What's the difference between using obj-c accessors and using dot syntax?In the latter case, you'll receive a float boxed as an NSNumber..

72 out of 100 based on 17 user ratings 392 reviews