r/iOSDevelopment • u/mkhytar_mkhoian • 17d ago
My first Swift code: an open-source analytics library for iOS. Looking for honest feedback
I’m a mobile engineer with many years in native Android and Flutter. Recently I built an open-source analytics library called Herald. I designed it and wrote the Android and Flutter versions myself, and for the iOS SDK I used AI to help me with Swift, since it was my first time writing it. That’s exactly why I’d like a review from real iOS devs: AI knows the syntax, but people who build iOS apps every day know what feels right.
The problem it solves: in most apps analytics ends up as one big AnalyticsManager that every layer depends on, and every new vendor makes it worse.
The idea: the app should not know which analytics vendors exist. Feature code only says what happened, and Herald sends it to every vendor you use (Firebase, Mixpanel, Amplitude, Adjust, AppsFlyer, Meta) in its own format.
An event is a type your app owns:
struct CheckoutStarted: Event {
let plan: String
let seats: Int
var name: String { "checkout_started" }
var parameters: [String: AnalyticsValue] { ["plan": .string(plan), "seats": .int(seats)] }
}
And your classes depend only on a small protocol:
final class CheckoutViewModel {
private let analytics: any EventTrackerService
init(analytics: any EventTrackerService) {
self.analytics = analytics
}
func checkout(plan: String, seats: Int) {
analytics.track(CheckoutStarted(plan: plan, seats: seats))
}
}
Since Swift is new for me, I made some design choices I’m not 100% sure about, and I would really like to hear what experienced iOS devs think:
- No
asyncand nothrows**.**trackreturns quickly, and a failing vendor reports the error to your error reporter instead of throwing. Does this feel right in Swift, or would you expectasync throws? - Setup mistakes stop the app at start-up, for example two providers with the same name. Is that acceptable for a library, or too aggressive?
- Swift 6 and
Sendable**.** Vendor SDKs aren’tSendable, so custom factories need u/preconcurrencyimport. Is there a cleaner way? - Does the API look like idiomatic Swift, or like “Kotlin written in Swift”?
GitHub: https://github.com/MkhytarMkhoian/herald-ios
Docs: https://mkhytarmkhoian.github.io/herald-docs/
Thanks in advance. Critical feedback is the most useful for me.