{"id":20678949,"url":"https://github.com/fastred/storyboarddependencyinjectiontemplates","last_synced_at":"2026-03-15T08:03:18.269Z","repository":{"id":148118994,"uuid":"113197577","full_name":"fastred/StoryboardDependencyInjectionTemplates","owner":"fastred","description":"Code generation of initializers for storyboard-based view controllers","archived":false,"fork":false,"pushed_at":"2017-12-06T14:24:36.000Z","size":9,"stargazers_count":19,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T19:33:28.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://holko.pl/2017/12/06/future-proof-dependency-injection/","language":"HTML","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/fastred.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":"2017-12-05T15:12:49.000Z","updated_at":"2022-01-20T16:33:27.000Z","dependencies_parsed_at":"2023-07-06T10:16:00.235Z","dependency_job_id":null,"html_url":"https://github.com/fastred/StoryboardDependencyInjectionTemplates","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fastred/StoryboardDependencyInjectionTemplates","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastred%2FStoryboardDependencyInjectionTemplates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastred%2FStoryboardDependencyInjectionTemplates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastred%2FStoryboardDependencyInjectionTemplates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastred%2FStoryboardDependencyInjectionTemplates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastred","download_url":"https://codeload.github.com/fastred/StoryboardDependencyInjectionTemplates/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastred%2FStoryboardDependencyInjectionTemplates/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269956177,"owners_count":24503116,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-16T21:23:16.197Z","updated_at":"2026-03-15T08:03:13.237Z","avatar_url":"https://github.com/fastred.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StoryboardDependencyInjectionTemplates\n\nThis repository provides templates for [Sourcery](https://github.com/krzysztofzablocki/Sourcery). They allow you to code generate initializers for storyboard-based view controllers.\n\n# StoryboardDependencyInjection.ejs\n\n1. Add the following protocol to your project:\n    ```swift\n    protocol StoryboardInitializable where Self: UIViewController {\n        static func instantiateFromStoryboard() -\u003e Self\n    }\n    ```\n2. Conform view controllers to it.\n3. Use this template with [Sourcery](https://github.com/krzysztofzablocki/Sourcery).\n\n### Example\n\nFor the following view controller:\n\n```swift\nfinal class ProfileViewController: UIViewController, StoryboardInitializable {\n    var viewModel: ProfileViewModel!\n\n    static func instantiateFromStoryboard() -\u003e ProfileViewController {\n        let storyboard = UIStoryboard(name: \"Profile\", bundle: Bundle.main)\n        return storyboard.instantiateViewController(withIdentifier: \"profileViewController\") as! ProfileViewController\n    }\n}\n```\n\nSourcery will generate `StoryboardDependencyInjection.generated.swift` with:\n\n```swift\n// MARK: - ProfileViewController - StoryboardDependencyInjection\nextension ProfileViewController {\n\n    static func makeFromStoryboard(\n        viewModel: ProfileViewModel\n    ) -\u003e ProfileViewController {\n        let viewController = StoryboardScene.Profile.instantiateProfileViewController()\n        viewController.setDependencies(\n            viewModel: viewModel\n        )\n        return viewController\n    }\n\n    func setDependencies(\n        viewModel: ProfileViewModel\n    ) {\n        self.viewModel = viewModel\n    }\n}\n```\n\nNow, use `makeFromStoryboard(viewModel:)` to create instances of `ProfileViewController`.\nWhen you add a new implicitly unwrapped optional property to that view controller, the definition of this method will automatically update, and the Swift compiler will let you know about all call sites needing update.\n\n# StoryboardDependencyInjectionWithSwiftGen.ejs\n\n1. Add the following empty protocol to your project:\n    ```swift\n    protocol StoryboardInitializable where Self: UIViewController { }\n    ```\n2. Conform view controllers to it.\n3. Set up and run [SwiftGen](https://github.com/SwiftGen/SwiftGen).\n4. Use this template with [Sourcery](https://github.com/krzysztofzablocki/Sourcery).\n\n### Example\n\nFor the following view controller:\n\n```swift\nfinal class ProfileViewController: UIViewController, StoryboardInitializable {\n    var viewModel: ProfileViewModel!\n}\n```\n\nSourcery will analyze your code and code generated by SwiftGen (`enum StoryboardScene`) and generate `StoryboardDependencyInjectionWithSwiftGen.generated.swift` with:\n\n```swift\n// MARK: - ProfileViewController - StoryboardDependencyInjection\nextension ProfileViewController {\n\n    static func makeFromStoryboard(\n        viewModel: ProfileViewModel\n    ) -\u003e ProfileViewController {\n        let viewController = StoryboardScene.Profile.instantiateProfileViewController()\n        viewController.setDependencies(\n            viewModel: viewModel\n        )\n        return viewController\n    }\n\n    func setDependencies(\n        viewModel: ProfileViewModel\n    ) {\n        self.viewModel = viewModel\n    }\n}\n```\n\nNow, use `makeFromStoryboard(viewModel:)` to create instances of `ProfileViewController`.\nWhen you add a new implicitly unwrapped optional property to that view controller, the definition of this method will automatically update, and the Swift compiler will let you know about all call sites needing update.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastred%2Fstoryboarddependencyinjectiontemplates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastred%2Fstoryboarddependencyinjectiontemplates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastred%2Fstoryboarddependencyinjectiontemplates/lists"}