Open mlch911 opened 7 months ago
Regardless of Macro, it should not be possible to capture self
before Self
is initialized.
How about modifying it to assign after initialization as follows?
import UIKit
extension UIView {
func bk_(whenTapped: () -> Void) {}
}
extension UIViewController {
@AssociatedObject(.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
private var autoMaskView: UIView?
func setup() {
autoMaskView = { [self] in
let ss = self
let view = NSView()
view.bk_(whenTapped: { [weak ss] in
self?.window?.endEditing(true)
})
return view
}()
}
}
So the Macro is build before Self
is initialized. It's different from just using a computing property, right?
So if I want to capture self
, I can't use @AssociatedObject
.
This code get an error:
Value of type '(UIView) -> () -> UIView' has no member 'window'
But after I replace the code with the macro expaned code, the error goes away.🤣