{"id":18073984,"url":"https://github.com/levibostian/swapper-ios","last_synced_at":"2025-04-12T05:42:07.681Z","repository":{"id":35055442,"uuid":"200923824","full_name":"levibostian/Swapper-iOS","owner":"levibostian","description":"Swap between many different UIViews within your app quick and easy.","archived":false,"fork":false,"pushed_at":"2022-04-05T22:23:14.000Z","size":743,"stargazers_count":3,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T05:42:02.494Z","etag":null,"topics":["cocoapods","ios","ios-lib","swift"],"latest_commit_sha":null,"homepage":"https://levibostian.github.io/Swapper-iOS/index.html","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/levibostian.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":"2019-08-06T21:00:03.000Z","updated_at":"2021-06-05T19:12:55.000Z","dependencies_parsed_at":"2022-08-08T04:15:32.424Z","dependency_job_id":null,"html_url":"https://github.com/levibostian/Swapper-iOS","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levibostian%2FSwapper-iOS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levibostian%2FSwapper-iOS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levibostian%2FSwapper-iOS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levibostian%2FSwapper-iOS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/levibostian","download_url":"https://codeload.github.com/levibostian/Swapper-iOS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525162,"owners_count":21118616,"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":["cocoapods","ios","ios-lib","swift"],"created_at":"2024-10-31T10:10:47.893Z","updated_at":"2025-04-12T05:42:07.659Z","avatar_url":"https://github.com/levibostian.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/levibostian/Swapper-iOS.svg?branch=master)](https://travis-ci.com/levibostian/Swapper-iOS)\n[![Version](https://img.shields.io/cocoapods/v/Swapper.svg?style=flat)](https://cocoapods.org/pods/Swapper)\n[![License](https://img.shields.io/cocoapods/l/Swapper.svg?style=flat)](https://cocoapods.org/pods/Swapper)\n[![Platform](https://img.shields.io/cocoapods/p/Swapper.svg?style=flat)](https://cocoapods.org/pods/Swapper)\n![Swift 5.0.x](https://img.shields.io/badge/Swift-5.0.x-orange.svg)\n\n# Swapper\n\nSwap between many different UIViews within your app quick and easy.\n\n![project logo](misc/header.jpg)\n\n*Android developer? Check out [the Android version of Swapper!](https://github.com/levibostian/swapper-android)*\n\n## What is Swapper?\n\nYou know those moments in your app when you have a `UITableView` that has no rows to show? You know those moments when you perform a HTTP network request and you want to show a non-blocking loading view to the user? These are very common scenarios for mobile apps. Swapper is a `UIView` that allows you to swap between a set of other `UIView`s with just 1 line of code. \n\n## Why use Swapper?\n\n* Swift API\n* Lightweight. Zero dependencies. \n* UI testing friendly. \n* Setup with default values that should work for 95% of your use cases. Customizable for those other cases. \n* Full test suite. [![Build Status](https://travis-ci.com/levibostian/Swapper-iOS.svg?branch=master)](https://travis-ci.com/levibostian/Swapper-iOS)\n* [Full documentation](https://levibostian.github.io/Swapper-iOS/). \n\nI recommend you check out 2 other libraries that work nicely with Swapper: [Empty](https://github.com/levibostian/Empty-iOS) and [PleaseHold](https://github.com/levibostian/PleaseHold-iOS).\n\n## Installation\n\nSwapper is available through [CocoaPods](https://cocoapods.org/pods/Swapper). To install it, simply add the following line to your Podfile:\n\n```ruby\npod 'Swapper', '~\u003e version-here'\n```\n\nReplace `version-here` with: [![Version](https://img.shields.io/cocoapods/v/Swapper.svg?style=flat)](https://cocoapods.org/pods/Swapper) as this is the latest version at this time. \n\n# Getting started\n\n* Create an instance of `SwapperView` in your `UIViewController`. You can do this with Storyboard by adding a `UIView` to Storyboard and setting the `UIView` class to `SwapperView`, or create an instance in your Swift code:\n\n```swift\nlet swapperView: SwapperView\u003cViewControllerSwapViews\u003e = {\n    let view = SwapperView\u003cViewControllerSwapViews\u003e()\n    view.translatesAutoresizingMaskIntoConstraints = false\n    view.backgroundColor = .white\n    return view\n}()\n```\n\n* Make sure to create the `UIView`s that you want to swap between. In this example, let's assume that I created a `UITableView` and a `UIImageView` that I want to swap between.\n\nIn your `UIViewController`, add your `UIView`s to your `SwapperView`:\n\n```swift\nimport Swapper\n\n// It's recommended to use emum for the identifier. It will prevent bugs by not worrying about typos. \n// However, you can just as easily use `SwapperView\u003cString\u003e` or something similar. \nenum ViewControllerSwapViews: String, CustomStringConvertible {\n    case imageView\n    case tableView\n\n    var description: String {\n        return rawValue\n    }\n}\n\nclass ViewController: UIViewController {\n\n    let swapperView = SwapperView\u003cViewControllerSwapViews\u003e()\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        // `setSwappingViews` will remove all subviews from the SwapperView. Reset it. \n        swapperView.setSwappingViews([\n            (.imageView, myImageView),\n            (.tableView, myTableView)\n        ], swapTo: .imageView) // `swapTo` is optional and is used to swap to one of the views after setting new swapping views. \n    }\n\n}\n```\n\n*Note:*  Swapper holds onto `UIView` instances given with `setSwappingViews()` as a weak reference. Keep your own strong reference to make sure the app is working. \n\n*Note:* Swapper will update the AutoLayout constraints of the `UIView`s you set as the swapping views. Swapper will set the size as the same size you set as the `SwapperView`. Therefore, no need to set AutoLayout constraints on your own! If you're not using AutoLayout, edit the configuration for `SwapperView` to not update the constraints: `SwapperView.defaultConfig.updateAutoLayoutConstraints = false`.\n\n* Lastly, all you need to do is to tell Swapper to swap!\n\n```swift\ntry! swapperView.swapTo(.tableView)\n```\n\nSwapper will now show the `UITableView` for you. Swapper will even fade out the `UIImageView` and fade in the `UITbleView` for you for a nice touch 👌. If you want to override the default animation, you can override the behavior yourself:\n\n```swift\nSwapperView.defaultConfig.swapToAnimateOldView = { oldView in\n    // Run `UIView.animate()` function here on `oldView` to animate it out. \n}\nSwapperView.defaultConfig.swapToAnimateNewView = { newView in\n    // Run `UIView.animate()` function here on `newView` to animate it in. \n}\n```\n\n*Note:* `.swapTo()` will thrown an error if the id passed in was not given in `.setSwappingViews()`. Or, the view you passed in has been garbage collected. Swapper only keeps weak references to given `UIView`s. \n\n# Configure Swapper \n\nSwapper works great without any configuration necessary. However, if you wish to customize it yourself, you can. \n\nIf you want to change the default values of all instances of `SwapperView` in your app, change the values in the default singleton:\n\n```swift\nSwapperView.defaultConfig.transitionAnimationDuration = 0.8\n```\n\nOr, you can configure 1 single instance of `SwapperView`:\n\n```swift\nlet swapperView = SwapperView()\nvar instanceConfig: SwapperViewConfig {\n    let config = SwapperViewConfig()\n    config.backgroundColor = instanceConfigBackgroundColor\n    return config\n}\nswapperView.config = instanceConfig\n```\n\nFor a list of all the configuration options, view the [docs on SwapperViewConfig](https://levibostian.github.io/Swapper-iOS/Classes/SwapperViewConfig.html)\n\n# Testing with Swapper \n\nIf you want to write tests for your app and include Swapper in it, it's highly recommended to disable animations. \n\n```swift\nUIView.setAnimationsEnabled(false)\n```\n\nDone! Swapper inherits this property and will enable or disable animations with this setting. \n\n## Example\n\nSwapper comes with an example app you can use to play with the library. To run the example project, clone the repo, and run `pod install` from the Example directory first. Then, open the workspace in XCode. \n\n## Development \n\nSwapper is a pretty simple CocoaPods library project. Follow the directions below for the optimal development experience. \n\n* Install cocoapods/gems and setup workspace:\n\n```bash\n$\u003e bundle install\n$\u003e cd Swapper/Example\n$\u003e pod install\n$\u003e brew install swiftformat\n$\u003e brew install swiftlint\n```\n\n* Setup git hooks to run misc tasks for you when using git. \n\n```bash\n$\u003e brew install pre-commit\n$\u003e ./hooks/autohook.sh install\n```\n\nThe git hook scripts are installed in `hooks/`. View them if you wish. \n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n## Contribute\n\nSwapper is open for pull requests. Check out the [list of issues](https://github.com/levibostian/swapper-ios/issues) for tasks I am planning on working on. Check them out if you wish to contribute in that way.\n\n**Want to add features to Swapper?** Before you decide to take a bunch of time and add functionality to the library, please, [create an issue](https://github.com/levibostian/swapper-iOS/issues/new) stating what you wish to add. This might save you some time in case your purpose does not fit well in the use cases of Swapper.\n\n## License\n\nSwapper is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevibostian%2Fswapper-ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevibostian%2Fswapper-ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevibostian%2Fswapper-ios/lists"}