Normally there is one environment (Directory, UserDefaults, Cookies, Cache, …) for one app. To have multiple environments for debugging or to handle multiple accounts, multiple identical apps must be installed. (with different bundle IDs). In debugging, there may be cases where accounts are repeatedly checked by logging in and logging out.
Therefore, we thought it would be possible to create multiple environments within the same app and switch between them easily. This is why we created this library called AppContainer.
Demo
Default
Debug1
Selet Container
Container List
Container Info
Document
AppGroup
extension AppContainer {
static let group = .init(groupIdentifier: "YOUR APP GROUP IDENTIFIER")
}
Methods
Create New Container
let container = try AppContainer.standard.createNewContainer(name: "Debug1")
Get Container List
The original container is named DEFAULT and has a UUID of 00000000-0000-0000-0000-0000-0000-00000000000000000000.
You can check it with the property isDefault.
let containers: [Container] = AppContainer.standard.containers
Get Active Container
let activeContainer: Container? = AppContainer.standard.activeContainer
Activate Contrainer
It is recommended to restart the application after calling this method.
Revert to the state before this library was used.
Specifically, the DEFAULT container will be enabled and all other AppContainer-related files will be removed.
try AppContainer.standard.reset()
Notification
You can receive notifications when switching containers. If you want to add additional processing to be done strictly before and after the switch, use delegate as described below.
containerWillChangeNotification
Before container switching
containerDidChangeNotification
After container change
Delegate
Delegate can be used to add optional processing when switching containers.
The actions are performed in the following order.
// the `activate` method is called
// ↓↓↓↓↓↓↓↓↓↓
func appContainer(_ appContainer: AppContainer, willChangeTo toContainer: Container, from fromContainer: Container?) // Delegate(before container switch)
// ↓↓↓↓↓↓↓↓↓↓
// Container switching process (library)
// ↓↓↓↓↓↓↓↓↓↓
func appContainer(_ appContainer: AppContainer, didChangeTo toContainer: Container, from fromContainer: Container?) // Delegate (after container switch)
This library allows multiple delegates to be set.
Add the following.
AppContainer.standard.delegates.add(self) // if self is AppContainerDelegate compliant
It is held in a weak reference and will be automatically released when the object is freed. If you want to unset the delegate, write the following.
AppContainer.standard.delegates.remove(self) // if self conforms to AppContainerDelegate
AppContainerUI
Provides UI for using AppContainer. SwiftUI and UIKit are supported.
SwiftUI
import AppContainerUI
// show Container List
ContainerListView(appContainer: .standard, title: String = "Containers")
// container info view
ContainerInfoView(appContainer: .standard, container: container)
UIKit
import AppContainerUI
// show Container List
ContainerListViewController(appContainer: .standard, title: String = "Containers")
// container info view
ContainerInfoViewController(appContainer: .standard, container: container)
AppContainer
This library allows you to create and manage multiple environments with a single application, just as if you were swapping containers.
This is useful when you want to test multiple accounts in a staging application.
Concept
Normally there is one environment (Directory, UserDefaults, Cookies, Cache, …) for one app.
To have multiple environments for debugging or to handle multiple accounts, multiple identical apps must be installed. (with different bundle IDs).
In debugging, there may be cases where accounts are repeatedly checked by logging in and logging out.
Therefore, we thought it would be possible to create multiple environments within the same app and switch between them easily.
This is why we created this library called
AppContainer
.Demo
Document
AppGroup
Methods
Create New Container
Get Container List
The original container is named
DEFAULT
and has a UUID of00000000-0000-0000-0000-0000-0000-00000000000000000000
. You can check it with the propertyisDefault
.Get Active Container
Activate Contrainer
It is recommended to restart the application after calling this method.
Delete Container
If the container you are deleting is in use, activate the Default container before deleting it.
Clean Container
Reset
Revert to the state before this library was used. Specifically, the DEFAULT container will be enabled and all other AppContainer-related files will be removed.
Notification
You can receive notifications when switching containers.
If you want to add additional processing to be done strictly before and after the switch, use delegate as described below.
Delegate
Delegate can be used to add optional processing when switching containers. The actions are performed in the following order.
This library allows multiple delegates to be set. Add the following.
It is held in a weak reference and will be automatically released when the object is freed.
If you want to unset the delegate, write the following.
AppContainerUI
Provides UI for using AppContainer.
SwiftUI and UIKit are supported.
SwiftUI
UIKit
Licenses
MIT License