Swift Macros vs Sourcery Karşılaştırması
Swift 5.9+ compile-time native macros
VS
Sourcery
External Swift code generation tool (Stencil-based)
8 dk okumaiOS
Puan Karşılaştırması
Grafik yükleniyor...
Detaylı Puanlama
Performans
Swift Macros9/10
Sourcery7/10
Öğrenme Kolaylığı
Swift Macros7/10
Sourcery8/10
Ekosistem
Swift Macros8/10
Sourcery8/10
Topluluk
Swift Macros8/10
Sourcery9/10
İş Pazarı
Swift Macros8/10
Sourcery6/10
Gelecek
Swift Macros10/10
Sourcery6/10
Artıları & Eksileri
Swift Macros
Artıları
- Swift compiler native — perfect integration
- Type-safe, syntax error'ları compile-time
- IDE support (Xcode auto-complete, navigate)
- @Observable, @Query, #Preview gibi built-in macro'lar
- SwiftUI, SwiftData, Testing framework'lerinde yaygın
- Async safe, Thread safe
- Platform-agnostic (iOS, macOS, Linux)
- Future-proof — Apple officially promoting
Eksileri
- Swift 5.9+ only (Xcode 15+)
- Öğrenme eğrisi SwiftSyntax API bilgisi gerektiriyor
- Debugging zor — macro expansion görmek için #expand
- Build time ekliyor (ilk build)
En Uygun
Yeni Swift 5.9+ projectsSwiftUI, SwiftData projectsLibrary/framework authorsType-safe DSL yaratmakApple official pattern (Testing framework)
Sourcery
Artıları
- Swift 5.0+ compatible (eski projects)
- External build phase — runtime'da değil
- Stencil template — intuitive
- AutoMockable, AutoLenses, AutoEquatable built-in annotations
- Xcode'a entegre (build phase script)
- Community templates geniş
- Generated code checked-in git (inspect edilebilir)
- Mocking için extensive support
Eksileri
- External dependency (Swift Macros native)
- Build phase ekliyor — cleaner integration yok
- Generated file'lar repo'da — review noise
- Swift type system limitations (macros'tan zayıf)
En Uygun
Legacy Swift projects (5.0-5.8)Extensive mocking (test suite)Cross-team boilerplate reductionSpecific generation patterns (Lens, Equatable)Migration öncesi bridge
Kod Karşılaştırması
Swift Macros
@freestanding(expression)
public macro Color(_ hex: String) -> Color = #externalMacro(
module: "MyMacros",
type: "ColorFromHexMacro"
)
// Usage:
let primary = #Color("#4A90E2")
// Compile-time expansion → UIColor(red: 0.29, green: 0.56, ...)Sourcery
// Sourcery annotation
// sourcery: AutoMockable
protocol UserService {
func fetchUser(id: String) async throws -> User
func updateUser(_ user: User) async throws
}
// Generated (auto) — MockUserService.generated.swift:
// class MockUserService: UserService { ... }Sonuç
Yeni Swift 5.9+ project → Macros zorunlu (native, future-proof). Legacy (5.0-5.8) → Sourcery pragmatik. Migration: Sourcery'i phase-out, Macros'a geçiş. 2027'de Sourcery kullanımı niche olacak.
Ücretsiz Danışmanlık AlSSS
Sıkça Sorulan Sorular
Evet, macros primary + Sourcery mocking için hybrid. Ama ideal tek tool.