bigtreenono
10/27/2015 - 1:26 AM

__attribute__((overloadable)) test

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;
}