Objective-C-Generics icon indicating copy to clipboard operation
Objective-C-Generics copied to clipboard

Collection properties of genericsable classes also forced to use protocol

Open nicked opened this issue 11 years ago • 2 comments

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

nicked avatar Jul 19 '13 18:07 nicked

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 *'

nicked avatar Jul 19 '13 19:07 nicked

Have that problem, too. Makes it unusable for me despite being an awesome idea!

futuretap avatar Aug 15 '13 12:08 futuretap