Post

Replies

Boosts

Views

Activity

Xcode cannot recognize generic methods
In objective-c, I created a category, like @interface NSArray <__covariant ObjectType> (ppEx) @end Look at this ObjectType, I wrote a method like - (NSArray *)pp_map:(id(^)(ObjectType element))block;which act like the map function in Swift. you can call it like NSArray <NSString *>*values = @[@"1", @"2", @"3", @"4"]; NSArray *valueMap = [values pp_map:^id _Nonnull(NSString * _Nonnull element) { return [NSString stringWithFormat:@"Hello %@", element]; }]; Now I need to add a property like mapBlock, I want to realize the same func; @property (nonatomic, copy) NSArray *(^mapBlock)(id(^paramBlock)(ObjectType element)); I did it. But when I call this method in Xcode, it can't complete automatically. values.mapBlock(^id _Nonnull(ObjectType _Nonnull element) { }) It's unable to recognize type NSString, and always show ObjectType which can cause error. I can manually change it to NSString, but it's too complicated. I think it's a problem of Xcode. Can anybody help me?
1
0
476
Jan ’24