Ios Dependency Injection
ASecurityHere’s a simple quick-start using protocol-based initializer injection first, then Factory for wiring: ```swift import UIKit import Factory protocol AnalyticsServiceProtocol { func logEvent(name: String) } final class AnalyticsService: AnalyticsServiceProtocol { func logEvent(name: String) { print("Logged: \(name)") } } final class HomeViewModel { private let analytics: AnalyticsServiceProtocol init(analytics: AnalyticsServiceProtocol) { self.analytics = analytics } func screenOpened() { anal...
- 584 stars
- 0 votes
- 0 copies
- 4 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 12 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill ios-dependency-injection --agent claude-codeAre you the author of Ios Dependency Injection?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-ios-dependency-injection-e20caa45)Here’s a simple quick-start using protocol-based initializer injection first, then Factory for wiring:
```swift
import UIKit
import Factory
protocol AnalyticsServiceProtocol {
func logEvent(name: String)
}
final class AnalyticsService: AnalyticsServiceProtocol {
func logEvent(name: String) {
print("Logged: \(name)")
}
}
final class HomeViewModel {
private let analytics: AnalyticsServiceProtocol
init(analytics: AnalyticsServiceProtocol) {
self.analytics = analytics
}
func screenOpened() {
analytics.logEvent(name: "home_opened")
}
}
extension Container {
var analyticsService: Factory<AnalyticsServiceProtocol> {
self { AnalyticsService() }.singleton
}
var homeViewModel: Factory<HomeViewModel> {
self { HomeViewModel(analytics: self.analyticsService()) }
}
}
final class HomeViewController: UIViewController {
@Injected(\.homeViewModel) private var viewModel
override func viewDidLoad() {
super.viewDidLoad()
viewModel.screenOpened()
}
}
```
Why this setup:
- Use initializer injection as the default.
- Depend on protocols, not concrete classes.
- Keep singleton scope for app-wide services like analytics.
- Avoid resolving dependencies inline inside business logic.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.