MirrorObject 1.1.0

MirrorObject 1.1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2018
SPMSupports SPM

Maintained by Matzo.



  • By
  • Matzo

MirrorObject

Mirroring dynamic properties automatically.

CI Status Version License Platform

Usage

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.

Requirements

  • iOS 8 or later

Installation

MirrorObject is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "MirrorObject"

Author

Matzo, [email protected]

License

MirrorObject is available under the MIT license. See the LICENSE file for more info.