{"id":1112,"url":"https://github.com/marty-suzuki/Continuum","last_synced_at":"2025-07-30T20:31:18.050Z","repository":{"id":56906608,"uuid":"120477765","full_name":"marty-suzuki/Continuum","owner":"marty-suzuki","description":"NotificationCenter based Lightweight UI / AnyObject binder.","archived":true,"fork":false,"pushed_at":"2018-02-27T17:54:57.000Z","size":448,"stargazers_count":80,"open_issues_count":0,"forks_count":4,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-18T03:38:21.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marty-suzuki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-06T15:20:16.000Z","updated_at":"2023-07-18T11:45:40.000Z","dependencies_parsed_at":"2022-08-20T19:50:20.784Z","dependency_job_id":null,"html_url":"https://github.com/marty-suzuki/Continuum","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FContinuum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FContinuum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FContinuum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FContinuum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marty-suzuki","download_url":"https://codeload.github.com/marty-suzuki/Continuum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228179194,"owners_count":17881139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:39.166Z","updated_at":"2024-12-04T19:32:53.594Z","avatar_url":"https://github.com/marty-suzuki.png","language":"Swift","funding_links":[],"categories":["EventBus"],"sub_categories":["Getting Started","Other free courses","Linter"],"readme":"# Continuum\n\n[![CI Status](http://img.shields.io/travis/marty-suzuki/Continuum.svg?style=flat)](https://travis-ci.org/marty-suzuki/Continuum)\n[![Version](https://img.shields.io/cocoapods/v/Continuum.svg?style=flat)](http://cocoapods.org/pods/Continuum)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/cocoapods/l/Continuum.svg?style=flat)](http://cocoapods.org/pods/Continuum)\n[![Platform](https://img.shields.io/cocoapods/p/Continuum.svg?style=flat)](http://cocoapods.org/pods/Continuum)\n\nNotificationCenter based Lightweight UI / AnyObject binder.\n\n```swift\nfinal class ViewController: UIViewController {\n\n    @IBOutlet weak var label: UILabel!\n\n    private let viewModel: ViewModel = ViewModel()\n    private let center = NotificationCenter()\n    private let bag = ContinuumBag()\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        center.continuum\n            .observe(viewModel.text, on: .main, bindTo: label, \\.text)\n            .disposed(by: bag)\n\n        viewModel.text.value = \"Binding this text to label.text!\"\n    }\n}\n\nfinal class ViewModel {\n    let text: Variable\u003cString\u003e\n\n    init() {\n        self.text = Variable(value: \"\")\n    }\n}\n```\n\n## Usage\n\n### 1. Observe object KeyPath and bind it to target KeyPath\n\nNotificationCenter's instance has `continuum` property. You can access Continuum functions from it.\n\n```swift\nlet center = NotificationCenter()\nlet observer = center.continuum.observe(viewModel, \\.text, on: .main, bindTo: label, \\.text)\n```\n\nAbove source code means `observe viewModel's text propety and bind that value to label's text property on main thread`.\nIf property is observed, current value comes immediately.\n\n#### Notify changes with `func post(keyPath:)`\n\nIf value changed, notify changes like this.\n\n```swift\nviewModel.text = \"Changed\"\ncenter.continuum.post(keyPath: \\ViewModel.text)\nprint(label.text) // Changed\n```\n\n### 2. Observe Constant / Variable and bind it to target KeyPath\n\nConstant / Variable are value wrapper. Variable has getter / setter. Constant has only getter.\n\n```swift\nlet center = NotificationCenter()\nlet text = Variable\u003cString\u003e(value: \"\")\nlet observer = center.continuum.observe(text, on: .main, bindTo: label, \\.text)\n```\n\nIf property is observed, current value comes immediately.\n\n### 3. Observe Constant / Variable and bind it to closure\n\nConstant / Variable are value wrapper. Variable has getter / setter. Constant has only getter.\n\n```swift\nlet center = NotificationCenter()\nlet text = Variable\u003cString\u003e(value: \"\")\nlet observer = center.continuum.observe(text, on: .main, onValueChange: { value in\n    // something to do\n})\n```\n\nIf property is observed, current value comes immediately.\n\n#### Notify changes with setter of value at Variable\n\nIf Variable's value is changed, `func post(name:object:)` is automatically executed.\n\n```swift\ntext.value = \"Changed\"\nprint(label.text) // Changed\n```\n\nIn addition, if Variable's value is changed, related Constant value is automatically changed.\n\n```swift\nlet center = NotificationCenter()\nlet variable = Variable\u003cString\u003e(value: \"\")\nlet constant = Constant\u003cString\u003e(variable: variable)\nlet observer = center.continuum.observe(constant, on: .main, bindTo: label, \\.text)\nvariable.value = \"Changed\"\nprint(label.text) // Changed\n```\n\n### Lifecycle of ContinuumObserver\n\n`func observe(_:,_:,on:,bindTo:,_:)` returns `ContinuumObserver`.\nIf `func cancel()` of `ContinuumObserver` called, observation is cancelled.\n\n```swift\nlet observer = center.continuum.observe(viewModel, \\.text, on: .main, bindTo: label, \\.text)\nobserver.cancel()\n```\n\nIf adding observer to `ContinumeBag`, observation is cancelled by lifecycle of `ContinumeBag`.\n\n```swift\nvar bag = ContinumeBag()\ncenter.continuum\n    .observe(viewModel, \\.text, on: .main, bindTo: label, \\.text)\n    .disposed(by: bag)\n\nbag = ContinumeBag() // previous instance of ContinumeBag is released and observation is cancelled.\n```\n\n## Example\n\n### Playground\n\nYou can try **Continuum** with Playground.\nOpen Continuum.xcworkspace and run build.\nYou can try like this.\n\n![](./Images/playground.png)\n\n### Example Project\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\nOpen ContinuumSample.xcworkspace and run build.\nYou can try a simple counter app like this.\n\n![](./Images/example.png)\n\n## Requirements\n\n- Xcode 9.2 or later\n- Swift 4.0.3 or later\n- iOS 10.0 or later\n\n## Installation\n\n### CocoaPods\n\nContinuum is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'Continuum'\n```\n\n### Carthage\n\nIf you’re using [Carthage](https://github.com/Carthage/Carthage), simply add Continuum to your `Cartfile`:\n\n```ruby\ngithub \"marty-suzuki/Continuum\"\n```\n\n## Author\n\nmarty-suzuki, s1180183@gmail.com\n\n## License\n\nContinuum is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty-suzuki%2FContinuum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarty-suzuki%2FContinuum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty-suzuki%2FContinuum/lists"}