swift 韩国国际志愿者组织,绑定

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 韩国国际志愿者组织,绑定相关的知识,希望对你有一定的参考价值。

import Foundation

extension NSObjectProtocol where Self: NSObject {

    func observe<A, Other>(_ keyPath: KeyPath<Self,A>,
                        writeTo other: Other,
                        _ otherKeyPath: ReferenceWritableKeyPath<Other,A>)
        -> NSKeyValueObservation
        where A: Equatable, Other: NSObjectProtocol 
    {
            return self.observe(keyPath, options: .new) { _, change in
                guard let newValue = change.newValue,
                    other[keyPath: otherKeyPath] != newValue else {
                        return // no change
                }
                other[keyPath: otherKeyPath] = newValue
            }
    }
 
    func bind<A, Other>(_ keyPath: ReferenceWritableKeyPath<Self,A>,
                           to other: Other,
                           _ otherKeyPath: ReferenceWritableKeyPath<Other,A>)
        -> (NSKeyValueObservation, NSKeyValueObservation)
        where A: Equatable, Other: NSObject
    {
        let one = self.observe(keyPath, writeTo: other, otherKeyPath)
        let two = other.observe(otherKeyPath, writeTo: self, keyPath)
        return (one,two)
    }
}
import Foundation

final class Sample: NSObject {
    @objc dynamic var name: String = ""
}

class MyObj: NSObject {
    @objc dynamic var test: String = ""
}

let sample = Sample()
let other = MyObj()

let observation = sample.bind(\Sample.name, to: other, \.test)
sample.name = "NEW"
other.test
other.test = "HI"
sample.name

以上是关于swift 韩国国际志愿者组织,绑定的主要内容,如果未能解决你的问题,请参考以下文章

韩国IT业是怎么走向国际我们须要学习什么

Hive国际志愿者招募|白云学院站!

我国主导的两项大数据国际标准即将正式发布

韩国警察厅举行2021年国际网络犯罪应对研讨会

韩国国际航空公司-生成Flickr缩短的URL

倒计时两周!北京世园会进行半负荷压力测试,三万人同时入园