{"id":18270056,"url":"https://github.com/stevencurtis/TwoWayBindingUIKit","last_synced_at":"2025-04-04T23:31:40.166Z","repository":{"id":107073574,"uuid":"312257334","full_name":"stevencurtis/TwoWayBindingUIKit","owner":"stevencurtis","description":"A compact two way binding library for UIKit","archived":false,"fork":false,"pushed_at":"2020-11-12T13:45:30.000Z","size":6,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-05T11:52:18.977Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevencurtis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-12T11:32:53.000Z","updated_at":"2022-05-18T01:09:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"de959810-d60e-4037-ae0a-c509584e0c7f","html_url":"https://github.com/stevencurtis/TwoWayBindingUIKit","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevencurtis%2FTwoWayBindingUIKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevencurtis%2FTwoWayBindingUIKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevencurtis%2FTwoWayBindingUIKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevencurtis%2FTwoWayBindingUIKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevencurtis","download_url":"https://codeload.github.com/stevencurtis/TwoWayBindingUIKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266476,"owners_count":20910831,"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-11-05T11:38:15.559Z","updated_at":"2025-04-04T23:31:40.160Z","avatar_url":"https://github.com/stevencurtis.png","language":"Swift","readme":"# Two-way binding with UIKit\n\nMVVM is a fantastic Architecture pattern for iOS, and is highly recommended to be used in your production code. However, if you do not implement the two-way binding your architecture better represents Model-View-Presenter (MVP).\n\nMany developers will rely on *RxSwift* and *RxCocoa* to implement bindings, which is a rather heavyweight solution to simply implement Two-way binding.\n\nThis library offers an alternative: provide Two-way bind in a small, tested library.\n\n## Installation\nThis library is intended to be installed as a Swift Package [guide](https://stevenpcurtis.medium.com/use-swift-package-manager-to-add-dependencies-b605f91a4990b605f91a4990?sk=adfd10c7d96557b37ba6ea0443145eb4), where you would add [https://github.com/stevencurtis/SwiftCoding/TwoWayBindingUIKit](https://github.com/stevencurtis/TwoWayBindingUIKit)\n\n\n\n## Usage\n**Bind to identical types**\nValues can be created as `MakeBindable`\n\n```swift\nvar value: MakeBindable\u003cString\u003e = MakeBindable(\"Test Value\")\nlazy var label: UILabel = {\n    let lab = UILabel()\n    return lab\n}()\n```\nwhich can then be bound to a `UIControl` using a keypath: Providing the input and output are the same type (in this case,  `String` is the type for `value` and the text of `label` is also a `String`)\n\n```swift\nvalue.bind(\\String.self, to: lab, \\.text)\n```\nOther uses include binding a `UIButton` and it's `isEnabled` property, for example:\n\n```swift\nvar buttonEnabled: MakeBindable\u003cBool\u003e = MakeBindable(true)\nbuttonEnabled.bind(\\Bool.self, to: button, \\.isEnabled)\n```\n\n**Map bound types**\nIf you would like to bind a value to a type that is different to that of the value, you need to provide a mapping function of the type `(T) -\u003e R?`.\n\nA series of these are provided in this library:\n\nMappers.transformBoolToStringFunction\nMappers.transformFloatToStringFunction\nMappers.transformIntToStringFunction\n\nWhich are then passed to the bind function. A good example of hte use of this is where we can bind a Boolean value to the text of a `UILabel`:\n\n```swift\nvar switchValue: MakeBindable\u003cBool\u003e = MakeBindable(true)\nviewModel.switchValue.bind(\n    \\Bool.self,\n    to: switchLabel,\n    \\.text,\n    mapper: Mappers.transformBoolToStringFunction )\n```\n\nIf you wish to use a mapper that is not provided, you may also use a mapper inline, and here is an example of how that may be implemented:\n\n```swift\nlet transformBoolToStringFunction: (Bool) -\u003e String = String.init(_:)\nviewModel.switchValue.bind(\\Bool.self, to: switchLabel, \\.text, mapper: transformBoolToStringFunction)\n```\n\n## Example Post\nThere is a full post regarding this library at [https://github.com/stevencurtis/SwiftCoding/TwoWayBinding](https://github.com/stevencurtis/SwiftCoding/TwoWayBinding)\n","funding_links":[],"categories":["etc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevencurtis%2FTwoWayBindingUIKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevencurtis%2FTwoWayBindingUIKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevencurtis%2FTwoWayBindingUIKit/lists"}