Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michto01/1b1c1a3a8e41d94b86bf0f950a64ab20 to your computer and use it in GitHub Desktop.
Save michto01/1b1c1a3a8e41d94b86bf0f950a64ab20 to your computer and use it in GitHub Desktop.
__attribute__((overloadable)) test
__attribute__((overloadable)) NSString *descriptionFromValue(float value) {
    return @(value).stringValue;
}
__attribute__((overloadable)) NSString *descriptionFromValue(NSRange range) {
    return NSStringFromRange(range);
}
__attribute__((overloadable)) NSString *descriptionFromValue(id object) {
    return [object description];
}

// And more...

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"%@", descriptionFromValue(1.0));
        NSLog(@"%@", descriptionFromValue(NSMakeRange(1, 2)));
        NSLog(@"%@", descriptionFromValue([NSObject new]));
    }
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment