Skip to content

Any idea why this is error. #21

@mlch911

Description

@mlch911

This code get an error: Value of type '(UIView) -> () -> UIView' has no member 'window'

@AssociatedObject(.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
private var autoMaskView: UIView = {
    let view = UIView()
    view.bk_(whenTapped: { [weak self] in
        self?.window?.endEditing(true)
    })
    return view
}()

But after I replace the code with the macro expaned code, the error goes away.🤣

static var __associated_autoMaskViewKey: UInt8 = 0
private var autoMaskView: UIView
{
    get {
        if let value = objc_getAssociatedObject(
            self,
            &Self.__associated_autoMaskViewKey
        ) as? UIView {
            return value
        }
        let value = {
            let view = UIView()
            view.bk_(whenTapped: { [weak self] in
                self?.window?.endEditing(true)
            })
            return view
        }()
        objc_setAssociatedObject(
            self,
            &Self.__associated_autoMaskViewKey,
            value,
            .OBJC_ASSOCIATION_RETAIN_NONATOMIC
        )
        return value
    }
    set {
        objc_setAssociatedObject(
            self,
            &Self.__associated_autoMaskViewKey,
            newValue,
            .OBJC_ASSOCIATION_RETAIN_NONATOMIC
        )
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions