Date
Sep. 8th, 2024
 
2024年 8月 6日

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.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系