gpt4 book ai didi

ios - 设置框架时weakSelf

转载 作者:行者123 更新时间:2023-11-28 20:07:29 25 4
gpt4 key购买 nike

我最近读了this post并认为使用文章中的技巧是个好主意。我在 block 中使用它,但我是否也应该在下面的“ block ”中使用它。下方的“方 block ”是真实方 block 吗?

avatar.frame = ({
CGRect frame = avatar.frame;
frame.origin.y = CGRectGetMaxY(self.view);
frame;
});

那会变成:

__weak typeof(self)weakSelf = self;
avatar.frame = ({
__strong typeof(weakSelf)strongSelf = weakSelf;

CGRect frame = avatar.frame;
frame.origin.y = CGRectGetMaxY(strongSelf.view);
frame;
});

最佳答案

这不是 block 。它是 GCC C 扩展,导致代码块 如果括在方括号和圆括号中则返回一个值。

This not only segregates configuration details into initialization, but the additional scope allows generic variable names like frame, button, and view to be reused in subsequent initializations. No more loginButtonFrame = ... / signupButtonFrame = ...!

来源:http://nshipster.com/new-years-2014/

关于ios - 设置框架时weakSelf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21604128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com