Skip to content

用 Swift 实现轻量的属性监听系统 - 循环引用 #16

@zyg-github

Description

@zyg-github

hello 看了https://github.com/nixzhu/dev-blog/blob/master/2015-04-30-property-listener.md 发现 vc 没有被释放
加上个了 引用列表 如下
UserInfo.name.bindAndFireListener("ThirdViewController.nameButton") { [weak self = self] name in
if let viewController = self {
viewController.nameButton.setTitle(name, forState: .Normal)
}
}

    UserInfo.hairColor.bindAndFireListener("ThirdViewController.backgroundColor") { [weak self = self] color in
        if let viewController  = self {
            viewController.view.backgroundColor = color
        }
    }

不过 我感觉还需要完善 比如当 ViewController 销毁了 应该把事件移出
感觉 还是 NSNotificationCenter 方便 哈哈~

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