苹果的文档中明确地写道:
You should decorate variables correctly. When using qualifiers in an object variable declaration,
the correct format is:“ClassName * qualifier variableName;”.
按照这个说明,要定义一个weak型的NSString引用,它的正确写法应该是:
NSString * __weak str = @"hehe";
但很多人,包括我自已都用了错误的写法是:
__weak NSString *str = @"hehe";
那这里就有疑问了,既然文档说是错误的,为啥编译器不报错呢?文档又解释道:
Other variants are technically incorrect but are “forgiven” by the compiler. To understand the issue, see http://cdecl.org/ .
You should decorate variables correctly. When using qualifiers in an object variable declaration,
the correct format is:“ClassName * qualifier variableName;”.
按照这个说明,要定义一个weak型的NSString引用,它的正确写法应该是:
NSString * __weak str = @"hehe";
但很多人,包括我自已都用了错误的写法是:
__weak NSString *str = @"hehe";
Other variants are technically incorrect but are “forgiven” by the compiler. To understand the issue, see http://cdecl.org/ .