Date
Nov. 23rd, 2024
 
2024年 10月 23日

Post: Objective-C: weakSelf

Objective-C: weakSelf

Published 12:01 Jan 05, 2016.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

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.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询