Last active
May 24, 2017 16:45
-
-
Save jayrhynas/1ca9ad29115fe5b7f7a9c7668fdd6cc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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; | |
} |
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
Crashes at line 34 with
Full output of
@encode(Struct3)
is{Struct3=^{Struct1}}