在看 Raywenderlich 的 RxSwift 教材,有一个写法看不懂

2017 年 9 月 30 日
 zenghaojim33
https://gist.github.com/zenghaojim33/a6990148ec50f615a9ded22d3d3ed554
5248 次点击
所在节点    iDev
12 条回复
zenghaojim33
2017 年 9 月 30 日
这里中括号后面的(self)是什么意思?_?
guitarkitten
2017 年 9 月 30 日
{ this in .... }(self) 这不就是一个调用么?
abcyuxue123
2017 年 9 月 30 日
感觉 ls +1

可以去掉 self 尝试运行,结果应该一样
zenghaojim33
2017 年 9 月 30 日
@guitarkitten 还是没理解。这个 in 前面的 this 对应的就是(self)吗?

@abcyuxue123 去掉 self 是运行不了的,会提示 this 没有定义
NxiJSiOS
2017 年 9 月 30 日
Since self is a struct you can ’ t create weak or unowned references. Instead, pass self to the closure or function that initialized the lazy variable.
zenghaojim33
2017 年 9 月 30 日
@NxiJSiOS 貌似明白了点,就是在 struct 里面直接使用 self 的话会报错必须这样传进去?
engHacker
2017 年 9 月 30 日
showme1121
2017 年 9 月 30 日
@zenghaojim33 this 是整个 closure 的参数啊
zenghaojim33
2017 年 10 月 1 日
@showme1121 但是( self )又是什么
airdrop
2017 年 10 月 11 日
closure 的调用吧
shawndev
2017 年 10 月 15 日
lazy var button : UIButton = {
$0.hide = true
}(UIButton())

和这种写法是一样的
zenghaojim33
2017 年 10 月 16 日
@shawndev 明白了,那如果把 UIButton()放到闭包里面是不是一样的?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/394821

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX