Should I declare it as

(#1) ClassName * __block variableName

or

(#2) __block ClassName * variableName

?

I seen a lot of code uses format #2, Including Apple's Blocks Programming Topics.

But recently I found Apple's "Transitioning to ARC Release Notes" says:

You should decorate variables correctly. When using qualifiers in an object variable declaration, the correct format is:

ClassName * qualifier variableName;

for example:

MyClass * __weak myWeakReference;

Other variants are technically incorrect but are “forgiven” by the compiler. To understand the issue, see http://cdecl.org/.

So I'm confused, Which format should I use in the future?

有帮助吗?

解决方案

They are essentially the same. I personally prefer placing __block at the beginning since it's more important than the variable's type.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top