Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C generics in blocks

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) {...};
like image 886
mllm Avatar asked Feb 04 '16 12:02

mllm


People also ask

Does Objective-C support generics?

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.

When to use blocks in Objective-C?

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 .


1 Answers

No. Objective-C generics are only for classes, not typedefs.

like image 59
newacct Avatar answered Oct 19 '22 06:10

newacct