LyargoOS
User Center
 

Date
Sep. 24th, 2026
 
2026年九月廿四

Post: Objective-C: weakSelf

Objective-C: weakSelf

Table of Content

The correct way to define a weak object is:

__typeof__(obj) __weak wobj = obj;

Note that having __weak before the type is technically incorrect.

However, you can find this in AFNetworking's AFURLConnectionOperation.m codes:

__weak __typeof(&*self)weakSelf = self;

But the __typeof__((__typeof__(self))self) trick is not necessary anymore in the clang version Apple clang version 4.0 and later, like Xcode 4.4+.

Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询