Despite its name, this question doesn't seem to address it.
Is it possible to use Objective-C generics with blocks?
Something like:
typedef void (^MyResultBlock<__covariant ObjectType>)(NSArray<ObjectType> *items);
...and then declaring a block:
MyResultBlock<NSNumber> blockName = ^void(NSArray<NSNumber> *items) {...};
Generics offers flexibility in programming and is a widely adopted pattern in many languages. For iOS developers, we all know Generics in Swift is super powerful. For Objective-C, does it has Generics as well? The answer is yes.
Blocks are a language-level feature added to C, Objective-C and C++, which allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. Blocks are Objective-C objects, which means they can be added to collections like NSArray or NSDictionary .
No. Objective-C generics are only for classes, not typedef
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With