{"id":13503884,"url":"https://github.com/Karumi/BothamUI","last_synced_at":"2025-03-29T18:31:35.859Z","repository":{"id":56903924,"uuid":"46490800","full_name":"Karumi/BothamUI","owner":"Karumi","description":"Model View Presenter Framework written in Swift.","archived":true,"fork":false,"pushed_at":"2018-11-19T09:41:53.000Z","size":15404,"stargazers_count":347,"open_issues_count":13,"forks_count":41,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-03T08:37:27.682Z","etag":null,"topics":["mvp","mvp-pattern"],"latest_commit_sha":null,"homepage":"http://karumi.com","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Karumi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-19T12:27:33.000Z","updated_at":"2024-10-30T12:56:20.000Z","dependencies_parsed_at":"2022-08-21T02:50:18.058Z","dependency_job_id":null,"html_url":"https://github.com/Karumi/BothamUI","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/Karumi%2FBothamUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Karumi%2FBothamUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Karumi%2FBothamUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Karumi%2FBothamUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Karumi","download_url":"https://codeload.github.com/Karumi/BothamUI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246227072,"owners_count":20743880,"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":["mvp","mvp-pattern"],"created_at":"2024-07-31T23:00:49.091Z","updated_at":"2025-03-29T18:31:30.850Z","avatar_url":"https://github.com/Karumi.png","language":"Swift","funding_links":[],"categories":["UI","Swift"],"sub_categories":[],"readme":"# ![Karumi logo][karumilogo]BothamUI [![Build Status](https://travis-ci.org/Karumi/BothamUI.svg?branch=ui-tests-and-travis-ci-support)](https://travis-ci.org/Karumi/BothamUI) [![CocoaPods Compatible](https://img.shields.io/cocoapods/v/BothamUI.svg)](https://img.shields.io/cocoapods/v/BothamUI.svg)\n\nBothamUI is MVP [(Model-View-Presenter)][mvp] framework written in Swift.\n\nThis project will help you setup all your presentation logic. BothamUI provides classes to represent the main components of this pattern like ``BothamViewController`` and ``BothamPresenter``.\n\nIn addition we will use a wireframe navigation model and a service locator example[[5] [di]].\n\n## Screenshots\n![Screenshot1][screenshot1]\n\nApplication UI/UX designs by [Luis Herrero][luisHerreroTwitterAccount].\n\nData provided by Marvel. © 2015 MARVEL\n\n\n## Usage\n\nThis framework contains all the classes needed to implement your presentation logic following the MVP pattern. To use the view package, make your ``ViewController`` extend from ``Botham ViewController`` and specify in the storyboard wich class and Storyboard ID is linked to:\n\n```swift\nimport BothamUI\n\nclass SampleViewController: BothamViewController {\n    /*...*/\n}\n```\n![storyboardReference]\n\n#### Storyboard\n\n`BothamStoryboard` provide a series of methods to help you instantiate view controllers by there storyboard ID. By default `instantiateViewController()` will search for view controller with the storyboard ID with the same name as the class.\n\n```swift\nimport BothamUI\n\nlet mainStoryboard = BothamStoryboard(name: \"Main\")\nlet viewController: SampleViewController = mainStoryboard.instantiateViewController(\"SampleViewController\")\nlet viewController: SampleViewController = mainStoryboard.instantiateViewController()\n```\n\n#### Presenter\nTo follow the MVP pattern, BothamUI also provides a ``BothamPresenter`` protocol that will be responsible for all your presentation logic. BothamUI will take care of linking your view (a ``BothamViewController``) with your presenter and subscribing it to its lifecycle. In order to do that, create a class that implement ``BothamPresenter`` and link it to your view:\n\n```swift\nimport BothamUI\n\nclass SamplePresenter: BothamPresenter {\n    private weak var ui: SampleUI?\n\n    init(ui: CharacterDetailUI) {\n        self.ui = ui\n    }\n    \n    func viewDidLoad() {\n        /* ... */\n    }\n}\n```\n\n```swift\nprotocol SampleUI: BothamUI {\n\t/* ... */\n}\n```\n```swift\nclass SampleViewController: BothamViewController, SampleUI {\n    /*...*/\n}\n```\n### Dependency injection\n\nBothamUI is built around the concept of dependency injection, all the dependencies are provided by constructor or properties, base on what UIKit allows us.\n\n#### ViewController Instantiation\n\nIn the example a Service Locator is used in order to instantiate view controllers, but you can also use [Swinject](https://github.com/Swinject/Swinject) or others DI frameworks.\n\n```swift\nclass ServiceLocator {\n\n    static let sharedInstance = ServiceLocator()\n\n    func provideSampleViewController() -\u003e SampleViewController {\n        let viewController: SampleViewController = provideMainStoryboard().viewController()\n        viewController.presenter = SamplePresenter(ui: viewController)\n        return viewController\n    }\n}\n```\n\n#### Lifecycle\n\nOnce both, view and presenter, are linked you can react to your view lifecycle directly from the presenter. You will be also able to call your view easily from the presenter:\n\n```swift\nclass SamplePresenter: BothamPresenter {\n    private weak var ui: SampleUI?\n\n    init(ui: CharacterDetailUI) {\n        self.ui = ui\n    }\n    \n    func viewDidLoad() {\n        self.ui?.showMessage(\"Welcome to Botham\")\n    }\n}\n```\n\nTo understand when the lifecycle methods are called take a look at the following table:\n\n| BothamPresenter       | UIViewController      |\n| --------------------- |-----------------------|\n| ``viewDidLoad``       | ``viewDidLoad``       |\n| ``viewWillAppear``    | ``viewWillAppear``    |\n| ``viewDidAppear``     | ``viewDidAppear ``    |\n| ``viewWillDisappear`` | ``viewWillDisappear`` |\n| ``viewDidDisappear``  | ``viewDidDisappear``  |\n\n\n### Caveats\n\n* ViewControllers instantiated view UIStoryboard, can't reference Generic Type.\n* Presenter and ViewController have a circular reference (like a ViewController and Datasource).\n\n\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 0.39.0+ is required to build BothamUI.\n\nTo integrate BothamUI into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\n\npod 'BothamUI', '~\u003e 1.0'\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\nDo you want to contribute?\n--------------------------\n\nFeel free to report us or add any useful feature to the library, we will be glad to improve it with your help.\n\nKeep in mind that your PRs **must** be validated by Travis-CI.\n\nLicense\n-------\n\n    Copyright 2015 Karumi\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n[mvp]: http://martinfowler.com/eaaDev/uiArchs.html#Model-view-presentermvp\n[karumilogo]: https://cloud.githubusercontent.com/assets/858090/11626547/e5a1dc66-9ce3-11e5-908d-537e07e82090.png\n[storyboardReference]: https://cloud.githubusercontent.com/assets/858090/11711471/f425f110-9f26-11e5-9ff3-d59b5a51308e.png\n[screenshot1]: ./art/screencast1.gif\n[luisHerreroTwitterAccount]: https://twitter.com/luishj\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKarumi%2FBothamUI","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKarumi%2FBothamUI","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKarumi%2FBothamUI/lists"}