{"id":13466207,"url":"https://github.com/dalu93/Each","last_synced_at":"2025-03-25T21:31:38.156Z","repository":{"id":56909641,"uuid":"70886240","full_name":"dalu93/Each","owner":"dalu93","description":"Elegant ⏱ interface for Swift apps","archived":false,"fork":false,"pushed_at":"2023-01-03T07:38:19.000Z","size":58,"stargazers_count":759,"open_issues_count":4,"forks_count":29,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-09-29T18:32:25.379Z","etag":null,"topics":["swift","timer"],"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/dalu93.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-10-14T07:40:32.000Z","updated_at":"2024-07-19T02:57:54.000Z","dependencies_parsed_at":"2023-02-01T05:31:26.900Z","dependency_job_id":null,"html_url":"https://github.com/dalu93/Each","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/dalu93%2FEach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalu93%2FEach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalu93%2FEach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dalu93%2FEach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dalu93","download_url":"https://codeload.github.com/dalu93/Each/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222091984,"owners_count":16929761,"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":["swift","timer"],"created_at":"2024-07-31T15:00:40.889Z","updated_at":"2024-10-29T18:31:22.486Z","avatar_url":"https://github.com/dalu93.png","language":"Swift","readme":"# Each\nElegant ⏱ interface for Swift apps\n\n[![BuddyBuild](https://dashboard.buddybuild.com/api/statusImage?appID=5805caae4b74d00100717ec7\u0026branch=master\u0026build=latest)](https://dashboard.buddybuild.com/apps/5805caae4b74d00100717ec7/build/latest)\n\nEach is a NSTimer bridge library written in Swift.\n\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Leaks](#leaks)\n- [License](#license)\n\n## Features\n\n- [x] Completely configurable timers\n- [x] Support for time intervals in ms, seconds, minutes and hours\n- [x] Fully extendable\n- [x] More readable and simple to use in comparison with NSTimer object\n\n## Requirements\n\n- iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+\n- Xcode 8.0+\n- Swift 3.0+\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\n\u003e CocoaPods 1.1.0+ is required to build Each.\n\nTo integrate Each into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '10.0'\nuse_frameworks!\n\ntarget '\u003cYour Target Name\u003e' do\npod 'Each', '~\u003e 1.2'\nend\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n### Carthage\n\nYou can use [Carthage](https://github.com/Carthage/Carthage) to install `Each` by adding it to your `Cartfile`:\n\n```\ngithub \"dalu93/Each\"\n```\n\n## Usage\n\n### Creating a new timer instance\n\n```swift\nlet timer = Each(1).seconds     // Can be .milliseconds, .seconds, .minute, .hours  \n```\n\n### Performing operations\n\n```swift\ntimer.perform {\n    // Do your operations\n    // This closure has to return a NextStep value\n    // Return .continue if you want to leave the timer active, otherwise\n    // return .stop to invalidate it\n}\n```\n\nIf you want to leave the memory management decision to the `Each` class, you can simply use the `perform(on: _)` method. \nIt requires that the parameter is an `AnyObject` instance.\n\n```swift\ntimer.perform(on: self) {\n    // Do your operations\n    // This closure has to return a NextStep value\n    // Return .continue if you want to leave the timer active, otherwise\n    // return .stop to invalidate it\n}\n```\n\n### Stopping the timer manually\n\n```swift\ntimer.stop()    // This stops immediately the timer\n```\n\n### Restarting the timer\n\nYou can restart the timer only after you stopped it. This method restarts the timer with the same\nperform closure.\n\n```swift\ntimer.restart()\n```\n\n## Leaks\nUnfortunately the interface doesn't help you with handling the memory leaks the timer\ncould create. In case of them, two workarounds are provided\n\n### Workaround 1\n\nUse the `perform(on: _)` method as explained in the [usage](#usage) section.\nPlease note that using this method, the `timer` isn't immediately deallocated when the `owner` is deallocated.\nIt will be deallocated when the `timer` triggers the next time and it will check whether the `owner` instance is still valid or not.\n\n### Workaround 2\n\nIn case you don't want to declare a property that holds the `Each` reference, create a normal `Each` timer in your method scope and return `.stop/true` whenever the `owner` instance is `nil`\n\n```swift\nEach(1).seconds.perform { [weak self] in\n    guard let _ = self else { return .stop }\n\n    print(\"timer called\")\n    return .continue\n}\n```\n\n90% of closures will call `self` somehow, so this isn't so bad\n\n### Workaround 3\n\nIn case the first workaround wasn't enough, you can declare a property that holds the `Each` reference and call the `stop()` function whenever the `owner` is deallocated\n\n```swift\nfinal class ViewController: UIViewController {\n    private let _timer = Each(1).seconds\n\n    deinit {\n        _timer.stop()\n    }\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        _timer.perform {\n            // do something and return. you can check here if the `self` instance is nil as for workaround #1\n        }\n    }\n}\n```\n\n## License\n\nEach is released under the MIT license. See LICENSE for details.\n","funding_links":[],"categories":["Libs","Thread [🔝](#readme)"],"sub_categories":["Thread"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalu93%2FEach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdalu93%2FEach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalu93%2FEach/lists"}