Created
June 30, 2022 18:49
-
-
Save kiarashvosough1999/69525017537c0165326f74c117adcfed to your computer and use it in GitHub Desktop.
Scene Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
final class SceneManager { | |
var activityIdentifier: ActivityIdentifier? { | |
options | |
.userActivities | |
.compactMap { ActivityIdentifier(rawValue: $0.activityType) } | |
.first | |
} | |
private let options: UIScene.ConnectionOptions | |
init(with options: UIScene.ConnectionOptions) { | |
self.options = options | |
} | |
func generateUISceneConfiguration() -> UISceneConfiguration { | |
let identifier = activityIdentifier ?? .mainApp | |
switch identifier { | |
case .mainApp: | |
return generateMainAppConfig(with: identifier.rawValue) | |
} | |
} | |
fileprivate func generateMainAppConfig(with identifier: String) -> UISceneConfiguration { | |
let config = UISceneConfiguration(name: identifier + " Configuration", | |
sessionRole: .windowApplication) | |
config.delegateClass = MainAppSceneDelegate.self | |
return config | |
} | |
} | |
extension SceneManager { | |
enum ActivityIdentifier: String { | |
case mainApp | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment