Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created February 24, 2016 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjolnir/353de6b5f451686580d8 to your computer and use it in GitHub Desktop.
Save fjolnir/353de6b5f451686580d8 to your computer and use it in GitHub Desktop.
KVC does not work with typedefs
#import <Foundation/Foundation.h>
typedef NSObject Foobar;
@interface Klass : Foobar
@property Foobar *baz;
@end
@implementation Klass
@end
int main(int argc, char *argv[]) {
@autoreleasepool {
Klass *obj = [Klass new];
NSLog(@"%s", @encode(typeof(obj.baz))); // Gets @encoded like `struct { NSObject } *`
obj.baz = @123;
NSLog(@"%@", obj.baz);
[obj setValue:@321 forKey:@"baz"]; // Crash
NSLog(@"%@", [obj valueForKey:@"baz"]); // Crash
}
}
@gin-melodic
Copy link

Use @compatibility_alias;
e.g. @compatibility_alias Foobar NSObject

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