Khan is a robust dependency management and initialization system for modular app components in Swift.
- Automated dependency resolution and initialization
- Circular dependency detection
- Comprehensive logging for debugging
- Debug mode shuffling to detect order-dependent issues
- Add the Khan framework to your project.
- Create initializers for your app components:
class DatabaseInitializer: Initializer {
static var dependencies: [Initializer.Type] = []
static func embark() async throws {
// Initialize database
}
}
- Create a Khan instance with your initializers:
let initializers: [Initializer.Type] = [
DatabaseInitializer.self,
NetworkingInitializer.self,
// Add other initializers
]
do {
let khan = try Khan(initializers: initializers)
try await khan.conquer()
} catch {
print("Initialization failed: \(error)")
}
- Khan will automatically resolve dependencies and initialize components in the correct order. Options
enableLogging
: Toggle logging on/off (default: true)
For complex dependency graphs, use khan.printDependencyTree()
to visualize the initialization order.
Add the dependency to your Package.swift
products: [
...
]
dependencies: [
.package(url: "https://github.com/kibotu/Khan", from: "1.0.0"),
],
targets: [
...
]
- iOS 16.0 or later
- Xcode 15.0 or later
- Swift 5.10 or later
Contributions welcome!
Copyright 2024 Jan Rabe & CHECK24 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.