Hello
For me more good use nested function instead of closure. How in this case right
way to define capture list?
//With Closure
class Sender {
var color = "Orange"
var writer = Receiver ()
func something() {
writer . callback = { [weak self ] newColor in
guard let strongSelf = self else { return }
strongSelf. color = newColor
}
}
}
class Receiver {
var callback: (( String ) -> Void )?
func somework() {
var color = "green"
guard let cb = callback else { return }
cb(color)
}
}
//Alternatively with Nested Function
class ASender {
var color = "Orange"
var writer = Receiver ()
func something() {
writer . callback = change
}
func change(name: String ) {
weak var n = self // is right or not?
guard let strongSelf = n else { return }
strongSelf. color = name
}
}
--
Alex Sedykh
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users