Section 2/171 menit
2. Masalah yang Dipecahkan
2. Masalah yang Dipecahkan
Masalah: Dependency Management Sebelum SPM
Sebelum SPM, ada tiga opsi untuk iOS/macOS:
- Manual — copy-paste source atau drag framework ke project. Sulit di-update, tidak ada versioning.
- CocoaPods — Ruby-based, modifikasi
.xcodeprojjadi.xcworkspace, sering konflik git. - Carthage — binary distribution, butuh manual setup di Xcode (Build Phases, search paths).
swift
# ❌ TANPA SPM (CocoaPods): Podfile + Ruby + .xcworkspace
platform :ios, '15.0'
target 'MyApp' do
use_frameworks!
pod 'Alamofire', '~> 5.6'
pod 'SwiftyJSON', '~> 5.0'
end
# Lalu jalankan: pod install (Ruby + ratusan transitive deps)
# Hasil: .xcworkspace yang harus dibuka, .xcproject termodifikasi
swift
// ✓ DENGAN SPM: satu file Swift, integrated ke Xcode
// File → Add Package Dependencies → URL → done
// Atau via Package.swift kalau project juga SPM package
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.6.0")
Masalah: Modularisasi App yang Sulit
Tanpa modularisasi yang proper, codebase besar jadi monolitik:
- Build time membengkak (whole-module rebuild).
- Coupling tinggi antar fitur.
- Sulit untuk parallel team development.
SPM membuat modularisasi via local package menjadi pattern standar:
swift
// ❌ TANPA modularisasi: satu Xcode target dengan ribuan file
// MyApp.xcodeproj:
// ├── Features/Login/...
// ├── Features/Home/...
// ├── Features/Profile/...
// └── ... (semua jadi satu binary, recompile penuh)
// ✓ DENGAN SPM modular: feature jadi local package
// MyApp.xcworkspace:
// ├── MyApp.xcodeproj (thin app shell)
// └── Modules/
// ├── LoginFeature (Package.swift)
// ├── HomeFeature (Package.swift)
// └── CoreUI (Package.swift)
// Build incremental per module, parallel compilation