Skip to content

Instantly share code, notes, and snippets.

@jayrhynas
Last active May 24, 2017 16:45
Show Gist options
  • Save jayrhynas/1ca9ad29115fe5b7f7a9c7668fdd6cc7 to your computer and use it in GitHub Desktop.
Save jayrhynas/1ca9ad29115fe5b7f7a9c7668fdd6cc7 to your computer and use it in GitHub Desktop.
//
// main.m
// MethodSignatureTest
//
// Created by Jayson Rhynas on 2017-04-03.
// Copyright © 2017 Jayson Rhynas. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef struct Struct1 {
int *member;
} Struct1;
typedef struct Struct2 {
Struct1 member;
} Struct2;
// This struct cannot be encoded
typedef struct Struct3 {
Struct1 *member;
} Struct3;
@interface MethodSignatureTest : NSObject
@end
@implementation MethodSignatureTest
- (instancetype)init
{
if (!(self = [super init])) return nil;
NSLog(@"%@", [self methodSignatureForSelector:@selector(testMethod1:)]); // Works
NSLog(@"%@", [self methodSignatureForSelector:@selector(testMethod2:)]); // Works
NSLog(@"%@", [self methodSignatureForSelector:@selector(testMethod3:)]); // Crashes here
return self;
}
- (void)testMethod1:(Struct1)strct {}
- (void)testMethod2:(Struct2)strct {}
- (void)testMethod3:(Struct3)strct {}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
[[MethodSignatureTest alloc] init];
}
return 0;
}
@jayrhynas
Copy link
Author

I can work around it by making the pointer to Struct1 a void * and casting where appropriate, but that's a pain and more error prone.

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