Skip to content

Instantly share code, notes, and snippets.

@numist
Last active December 13, 2015 16:48
Show Gist options
  • Save numist/4942399 to your computer and use it in GitHub Desktop.
Save numist/4942399 to your computer and use it in GitHub Desktop.
I'm not proud of this, but it's the cleanest answer available to me right now.
// It would be a mistake to use this code and expect it to work at any point in the future.
NSNumber *encoding_requiresStret(const char *encoding) {
NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:encoding];
// This information is obviously available internally, but it's only publicly exposed here.
NSString *signatureDescription = [signature debugDescription];
BOOL isStret = [signatureDescription rangeOfString:@"is special struct return? YES"].location != NSNotFound;
BOOL isNotStret = [signatureDescription rangeOfString:@"is special struct return? NO"].location != NSNotFound;
if (isStret) {
// objc_msgSend_stret will be used to invoke methods with this signature
return @YES;
} else if (isNotStret) {
// objc_msgSend will be used to invoke methods with this signature
return @NO;
} else {
// This is so fragile, I'm not even sure how I sleep at night. This is why we can't ship nice things.
return nil;
}
}
@numist
Copy link
Author

numist commented Sep 10, 2013

YES/NO/MAYBE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment