{"id":19252219,"url":"https://github.com/bellapplab/laziable","last_synced_at":"2025-07-20T01:09:25.828Z","repository":{"id":56919640,"uuid":"140805882","full_name":"BellAppLab/Laziable","owner":"BellAppLab","description":"When 'lazy var' doesn't cut it, have a truly Lazy variable in Swift.","archived":false,"fork":false,"pushed_at":"2019-04-29T17:27:46.000Z","size":160,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-21T22:07:03.925Z","etag":null,"topics":["carthage","cocoapods","ios","lazy","linux","macos","osx","swift","swift-package-manager","tvos","watchos"],"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/BellAppLab.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-07-13T06:22:32.000Z","updated_at":"2023-04-03T19:36:15.000Z","dependencies_parsed_at":"2022-08-20T21:50:16.588Z","dependency_job_id":null,"html_url":"https://github.com/BellAppLab/Laziable","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/BellAppLab/Laziable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FLaziable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FLaziable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FLaziable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FLaziable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BellAppLab","download_url":"https://codeload.github.com/BellAppLab/Laziable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FLaziable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266052548,"owners_count":23869478,"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":["carthage","cocoapods","ios","lazy","linux","macos","osx","swift","swift-package-manager","tvos","watchos"],"created_at":"2024-11-09T18:25:59.761Z","updated_at":"2025-07-20T01:09:25.786Z","avatar_url":"https://github.com/BellAppLab.png","language":"Swift","readme":"# Laziable [![Version](https://img.shields.io/badge/Version-1.1.0-black.svg?style=flat)](#installation) [![License](https://img.shields.io/cocoapods/l/Laziable.svg?style=flat)](#license)\n\n[![Platforms](https://img.shields.io/badge/Platforms-iOS|watchOS|tvOS|macOS|watchOS-brightgreen.svg?style=flat)](#installation)\n[![Swift support](https://img.shields.io/badge/Swift-3.3%20%7C%204.1%20%7C%204.2-red.svg?style=flat)](#swift-versions-support)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Laziable.svg?style=flat\u0026label=CocoaPods)](https://cocoapods.org/pods/Laziable)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Twitter](https://img.shields.io/badge/Twitter-@BellAppLab-blue.svg?style=flat)](http://twitter.com/BellAppLab)\n\n![Laziable](./Images/laziable.png)\n\nSo you declared a `lazy var` in Swift thinking it would behave like lazily instantiated variables in good ol' Objective-C. You thought you would set them to `nil` and they would reconstruct themselves later on when needed.\n\nYou poor thing.\n\n[They don't](https://stackoverflow.com/a/40847994).\n\nSo why not bring that awesomeness back to Swift in a very lightweight way?\n\n## Specs\n\n* iOS 9+\n* watchOS 3+\n* tvOS 9+\n* watchOS 3+\n* macOS 10.10+\n* Swift 4.2+\n\n## Usage\n\nDeclare your `Lazy` variable in one of the three ways provided:\n\n**Suggestion**: for the best results, use `let` when declaring your `Lazy` variables.\n\n```swift\nclass TestClass\n{\n    let lazyString = §{\n        return \"testString\"\n    }\n\n    let lazyDouble: Lazy\u003cDouble\u003e = Lazy {\n        return 0.0\n    }\n\n    let lazyArray = Lazy {\n        return [\"one\", \"two\", \"three\"]\n    }\n}\n```\n\nAccess your variable:\n\n```swift\nlet testObject = TestClass()\nprint(testObject.lazyString§) //prints out \"testString\"\n```\n\nSet your variable to `nil`, so it gets reconstructed again later:\n\n```swift\nlet testObject = TestClass()\ntestObject.lazyDouble §= nil\n```\n\n## Operators\n\n* `prefix §`\n  * Shorthand contructor for a `Lazy` variable:\n  \n```swift\nlet lazyThing = §{\n    return \u003c#code#\u003e\n}\n```\n\n* `postfix operator §`\n  * Shorthand accessor for `Lazy`:\n  \n```swift\nlet lazyString = §{\n    return \"Much cool\"\n}\n\nprint(lazyThing§) //prints out \"Much cool\"\n```\n\n* `infix operator §=`\n  * Shorthand assignment for `Lazy`:\n\n```swift\nlet lazyString = §{\n    return \"Much cool\"\n}\n\nlazyString §= nil //the string \"Much cool\" has been destroyed\nprint(lazyThing§) //reconstructs the string and prints out \"Much cool\"\n```\n\n## Notes\n\nFor the best results, use `let` when declaring your `Lazy` variables.\n\nAlso, make sure to use `[weak self]` or `[unowned self]` if capturing `self` in a `Lazy` variable's constructor.\n\n## Installation\n\n### Cocoapods\n\n```ruby\npod 'Laziable', '~\u003e 1.1'\n```\n\nThen `import Laziable` where needed.\n\n### Carthage\n\n```swift\ngithub \"BellAppLab/Laziable\" ~\u003e 1.1\n```\n\nThen `import Laziable` where needed.\n\n### Swift Package Manager\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/BellAppLab/Laziable\", from: \"1.1.0\")\n]\n```\n\nThen `import Laziable` where needed.\n\n### Git Submodules\n\n```\ncd toYourProjectsFolder\ngit submodule add -b submodule --name Laziable https://github.com/BellAppLab/Laziable.git\n```\n\nThen drag the `Laziable` folder into your Xcode project.\n\n## Author\n\nBell App Lab, apps@bellapplab.com\n\n### Credits\n\n[Logo image](https://thenounproject.com/search/?q=lazy\u0026i=1604294#) by [Georgiana Ionescu](https://thenounproject.com/georgiana.ionescu) from [The Noun Project](https://thenounproject.com/)\n\n## License\n\nLazy is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Flaziable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbellapplab%2Flaziable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Flaziable/lists"}