__strong and __weak keyword placement - Objective-C

后端 未结 2 2057
夕颜
夕颜 2020-12-31 19:19

The compiler seems to have no problem with the two following declarations:

NSObject * __weak weakThing;
__weak NSObject *anotherWeakThing;

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 19:45

    There is a difference if you have

     __weak NSObject *someWeakThing, *someSupposedlyButNotReallyWeakThing;
    

    because the __weak will only confusingly apply to the first variable. (this is a similar mistake to the rookie

    NSObject* one, two;
    

    which of course won't work as "expected", either).

提交回复
热议问题