Objective-C-Generics
Objective-C-Generics copied to clipboard
Collection properties of genericsable classes also forced to use protocol
Hi, thanks for the code, this could be really helpful!
I'm having a problem using Genericsable on classes which contain collection properties.
Say your MyClass example had another property, an NSArray called myArray. When I compile that, Xcode insists that any objects inside [MyClass myArray] also needs to be of type MyClass. Does this work for you?
Also, in your example you have an NSArray<NSString>
-- how do you genericise NSString or any built-in class?
Cheers, Nick
Just a code snippet in case I didn't explain it clearly :)
Add an array property to MyClass:
@interface MyClass : NSObject<MyClass>
@property (nonatomic, strong) NSString* name;
@property (nonatomic, strong) NSArray *arr;
@end
Then try putting any other object in arr
:
MyClass *cls = [MyClass new];
cls.arr = [NSArray arrayWithObject:@0];
And you'll get Incompatible pointer types sending 'NSNumber *' to parameter of type 'MyClass *'
Have that problem, too. Makes it unusable for me despite being an awesome idea!