{"id":18708861,"url":"https://github.com/igorkulman/simpleobservable","last_synced_at":"2025-04-12T10:34:54.207Z","repository":{"id":145188445,"uuid":"410329234","full_name":"igorkulman/SimpleObservable","owner":"igorkulman","description":"Very simple Observable and Publisher implementation for iOS apps.","archived":false,"fork":false,"pushed_at":"2021-09-27T12:17:20.000Z","size":9,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T05:41:52.242Z","etag":null,"topics":["ios","observable","publisher","reactive-programming","spm","swift","swiftpackage","swiftpackagemanager"],"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/igorkulman.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-25T16:50:27.000Z","updated_at":"2022-06-11T11:41:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"145b18c3-f436-4556-92cb-967b780bc028","html_url":"https://github.com/igorkulman/SimpleObservable","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkulman%2FSimpleObservable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkulman%2FSimpleObservable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkulman%2FSimpleObservable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkulman%2FSimpleObservable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorkulman","download_url":"https://codeload.github.com/igorkulman/SimpleObservable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248553794,"owners_count":21123521,"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":["ios","observable","publisher","reactive-programming","spm","swift","swiftpackage","swiftpackagemanager"],"created_at":"2024-11-07T12:25:30.064Z","updated_at":"2025-04-12T10:34:54.196Z","avatar_url":"https://github.com/igorkulman.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple observable\n\n![CI](https://github.com/igorkulman/SimpleObservable/workflows/CI/badge.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n![Platforms](https://img.shields.io/badge/platform-iOS-lightgrey.svg)\n[![Swift Version](https://img.shields.io/badge/Swift-5-F16D39.svg?style=flat)](https://developer.apple.com/swift)\n[![Twitter](https://img.shields.io/badge/twitter-@igorkulman-blue.svg)](http://twitter.com/igorkulman)\n\nVery simple `Observable` and `Publisher` implementation for iOS apps. \n\nUseful if you want to use a bit of simple reactive programming but do not want to add the full `RxSwift` or use `Combine`.\n\n## Observable\n\nCreate an `Observable` instance providing a default value.\n\n```swift\nlet isLoading = Observable\u003cBool\u003e(false)\n```\n\nyou can assign and read the value of this observable using the `value` property, for example when using it in a view model\n\n```swift\nisLoading.value = true\n```\n\nYou can bind to the value changes using the `bind` function, for example in a view controller\n\n```swift\nviewModel.isLoading.bind { [weak self] isLoading in\n    self?.loadingView.isHidden = !isLoading\n}\n```\n\nYou can also use a version of `bind` that accepts a keypath\n\n```swift\nviewModel.isLoading.bind(to: userDetailsView, keyPath: \\.isHidden)\n```\n\n## Publisher\n\n`Publisher` is an observable without an initial value. An `Observable` is used for storing state, a `Publisher` is used for events.\n\nAfter you create a `Publisher` instance\n\n```swift\nlet onError = Publisher\u003cError\u003e()\n```\n\nyou can publish new values to this publisher with the `publish` method, for example when using it in a view model\n\n```swift\nonError.publish(ApiError.InvalidCredentials)\n```\n\nYou can bind to the value changes using the `bind` function, for example in a view controller\n\n```swift\nviewModel.onError.bind { [weak self] error in\n    self?.showAlert(error)\n}\n```\n\n### ObservableButton\n\n`ObservableButton` can be created in code or used from a storyboard. You can use the `ObservableButton`  to easily subscribe to the tap event\n\n```swift\nloginButton.observable.tap.bind { [weak self] in\n    self?.login()\n}\n```\n\n### Good to know\n\nYou can bind to an observable or an publisher just once. This is not a technical limitation but a design decision.\n\nBoith observable and publisher always call the `bind` method on the main thread so no need to worry about binding changes to UI elements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkulman%2Fsimpleobservable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorkulman%2Fsimpleobservable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkulman%2Fsimpleobservable/lists"}