Objective-C General Covariant

Hiyas

I have this interface:

typedef void (^RMIteratorCompletionBlock) (void);

@interface RMAsyncIterator<__covariant T> : NSObject

+(RMAsyncIterator<T>*) iteratorWithArray:(NSArray<T>*) array;

-(id) init NS_UNAVAILABLE;
-(id) initWithArray:(NSArray*) array NS_DESIGNATED_INITIALIZER;

-(void) iterateWithWorkerBlock:(void (^) (T object, RMAsyncIterator<T>* iterator)) block withCompletionBlock:(RMIteratorCompletionBlock) completionBlock;
-(void) advance;
-(void) complete;

@end

now when i use this implementation method:

-(void) iterateWithWorkerBlock:(void (^) (id object, RMAsyncIterator* iterator)) block withCompletionBlock:(RMIteratorCompletionBlock) completionBlock {

I rightfully get a compiler warning about conflicting parameter types in the implementation of iterateWithWorkerBlock: withCompletionBlock:

The thing is, how the hell should you write this implementation method? I tried many different implementations, moving the type to typedef, because the type is not visible outside the scope of the interface using T, because the type of implementation is not executed, because, apparently, the implementation knows nada about its own interface type, using something like

-(void) iterateWithWorkerBlock:(void (^) (<__covariant T> object, RMAsyncIterator* iterator)) block withCompletionBlock:(RMIteratorCompletionBlock) completionBlock {

failed and I really don't know how to implement this method correctly. For the moment, I'm just using the id that gives me this warning, but I would like to get rid of the warning ...

Bueller? ?

+4
1

id

-(void) iterateWithWorkerBlock:(void (^) (id object, RMAsyncIterator* iterator)) block withCompletionBlock:(RMIteratorCompletionBlock) completionBlock {
0

Source: https://habr.com/ru/post/1657380/


All Articles