Compiler Error use @synthesizeAssociation in @safecategory
davidfuzju opened this issue · comments
#import "NSHTTPURLResponse+YTNetworkMethods.h"
#import <objc/runtime.h>
@safecategory(NSHTTPURLResponse, YTNetworkMethods)
@synthesizeAssociation(NSHTTPURLResponse, responsePlainBody)
@end
I got this compiler Error
Property declared in category 'YTNetworkMethods' cannot be implemented in class implementation
@SuperMarioBean Thats because really safecategory
is separate class, which methods will be injected to parent class NSHTTPURLResponse
. Really you can add properties like this:
@safecategory(NSHTTPURLResponse, YTNetworkMethods)
@end
@interface NSHTTPURLResponse_YTNetworkMethods_MethodContainer ()
@property (strong, nonatomic) NSData *responsePlainBody;
@end
@k06a thanks and btw why libextobjc use a separate class to implement the safe category, it's natural use @synthesizeAssociation in @safecategory because we add association properties in our categories.
with this implementation, we still write the repeat association property code
@synthesizeAssociation
macro can be allowed with code fix like this: https://github.com/k06a/libextobjc/compare/master...fix/associate-in-safecategory?quick_pull=1
But @synthesizeAssociation
still requires property
to be defined in @interface
part. Looks like we need @safecategory
which consists of two parts: interface and implementation like this:
@safecategory_interface(NSObject, MyCategory)
@property (strong, nonatomic) NSString *associatedString;
@end
@safecategory_implementation(NSObject, MyCategory)
@synthesizeAssociation(NSObject, associatedString);
@end