Mirroring dynamic properties automatically.
Update an dynamic property, then it will be reflected to other object which has same identifier.
let a = User("u1", followers: 0)
let b = User("u1", followers: 0)
print(a.followers) // -> 0
print(b.followers) // -> 0
a.followers += 1
print(a.followers) // -> 1
print(b.followers) // -> 1
User class is defined as following.
import MirrorObject
class User: NSObject, MirrorObject {
var id: String
dynamic var followers: Int
init(id: String, followers: Int) {
self.id = id
self.followers = followers
super.init()
self.startMirroring()
}
deinit {
self.stopMirroring()
}
func identifier() -> String {
return id
}
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 8 or later
MirrorObject is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "MirrorObject"
Matzo, [email protected]
MirrorObject is available under the MIT license. See the LICENSE file for more info.