Skip to content

Instantly share code, notes, and snippets.

@sunnyxx
Last active July 18, 2018 04:59
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save sunnyxx/26658b2aadc9b821fa0c to your computer and use it in GitHub Desktop.
Save sunnyxx/26658b2aadc9b821fa0c 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