Created
January 29, 2017 22:14
-
-
Save PaulTaykalo/3320996ec1fc2e233f97005675cc38b9 to your computer and use it in GitHub Desktop.
When floats stops working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| @implementation NSObject (Private) | |
| - (float)doSomethng { | |
| return 42.0; | |
| } | |
| @end | |
| int main(int argc, char * argv[]) { | |
| @autoreleasepool { | |
| NSObject * object = [NSObject new]; | |
| for (int i = 0; i < 10; i++) { | |
| float value = [object doSomethng]; | |
| printf("%f\n", value); | |
| [object performSelector:@selector(doSomethng) withObject:nil]; | |
| } | |
| for (int i = 0; i < 10; i++) { | |
| NSLog(@"Fix"); | |
| float value = [object doSomethng]; | |
| printf("%f\n", value); | |
| [object performSelector:@selector(doSomethng) withObject:nil]; | |
| } | |
| } | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When running code above, you'll see that after some point, every value you expect from the method, will return
NaNinstead of42Then in next cycle, you'll realize that you can fix this behavior just by adding
NSLogbefore calling method 🤷♂️Works on iPhone5 simulator only (Actually on any 32-bit simulators)
Output: