弱自引用的泛型typeof

编程入门 行业动态 更新时间:2024-10-11 09:19:19
本文介绍了弱自引用的泛型typeof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图找出一种方法使用 typeof 创建一个弱引用 self 块,以避免保留周期。

当我第一次读到这个,似乎约定是使用 __ block typeof(self)bself = self; ,它使用 __ block 进行编译,以避免保留周期不再工作, __ weak

但是 __ weak typeof(self)bself = self; 会导致错误:

类型'typeof(self)'(也称为'TUAccountsViewController * const __strong')已经设置了保留属性 $ b

有没有办法使用 typeof 或另一个调用来通常创建一个弱引用 self

解决方案

这样有效!

__ typeof __(o)__weak

我在我的BBlock项目中定义了 BBlockWeakSelf 可以这样使用:

BBlockWeakSelf wself = self;

github/kgn/BBlock/blob/master/BBlock.h

根据Aleph7编辑回应。

I am trying to figure out a way to use typeof to create a weak reference to self for use in blocks to avoid retain cycles.

When I first read about this it seems that the convention was to use __block typeof(self) bself = self;, which compiles but using __block to avoid retain cycles doesn't work anymore and __weak should be used instead.

However __weak typeof(self) bself = self; results in an error:

The type 'typeof (self)' (aka 'TUAccountsViewController *const __strong') already has retainment attributes set on it

Is there a way to use typeof or another call to generically create a weak reference to self?

解决方案

This works!

__typeof__(o) __weak

Which I've defined in my BBlock project as BBlockWeakSelf which can be used like this:

BBlockWeakSelf wself = self;

github/kgn/BBlock/blob/master/BBlock.h

Edited based on Aleph7's response.

更多推荐

弱自引用的泛型typeof

本文发布于:2023-11-08 06:40:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:typeof

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!