美文网首页
How Do I Declare A Block in Obje

How Do I Declare A Block in Obje

作者: 平谦 | 来源:发表于2018-05-09 17:21 被阅读18次

How Do I Declare A Block in Objective-C?

As a local variable:

returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};

As a property:

@property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);

As a method parameter:

- (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;

As an argument to a method call:

[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];

As a typedef:

typedef returnType (^TypeName)(parameterTypes); TypeName blockName = ^returnType(parameters) {...};

This site is not intended to be an exhaustive list of all possible uses of blocks.
If you find yourself needing syntax not listed here, it is likely that a typedef would make your code more readable.

Unable to access this site due to the profanity in the URL? http://goshdarnblocksyntax.com is a more work-friendly mirror.

<footer style="font-size: 12px; margin-top: 200px; opacity: 0.4; text-align: right; color: rgb(131, 148, 150); font-family: "Lucida Grande", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">By Mike Lazer-Walker, who has a very bad memory for this sort of thing.</footer>

相关文章

网友评论

      本文标题:How Do I Declare A Block in Obje

      本文链接:https://www.haomeiwen.com/subject/cirorftx.html