Is it possible for an instance of a UIView
to call a method which executes a closure, and inside that closure referring to the same instance? This is the non-generic version:
import UIKit
public extension UIView {
func layout(from: (UIView) -> ()) {
from(self)
}
}
When I call it with a UILabel for example, I do not have access to e.g. the text aligment. Is it possible that inside the closure I can refer to the UILabel? I would expect something like this would work:
func layout(from: (Self) -> ()) {
from(self)
}
But it doesn't compile. Is there a workaround? This is what I want:
let label = UILabel(frame: .zero)
label.layout { $0.textAlignment = .natural } // Currenly not working, since $0 = UIView.