Section 3/181 menit
3. Teori: Cara Kerja App Intents
3. Teori: Cara Kerja App Intents
Compile-Time Extraction
App Intents menggunakan Static Metadata Extraction — compiler Swift menganalisis code saat build dan mengekstrak metadata intent ke file .appintents yang di-bundle ke app. Sistem OS membaca metadata ini tanpa perlu menjalankan app, sehingga intent bisa muncul di Siri/Shortcuts bahkan sebelum app dibuka pertama kali.
swift
Build Time:
Swift Source → Compiler → .o files
→ AppIntents Metadata Extractor
→ MyApp.appintents (binary metadata)
→ bundled ke MyApp.app
Runtime:
OS reads .appintents → tampil di Shortcuts/Siri
User trigger intent → OS launch app in-process
→ App Intents runtime panggil perform()
Intent Lifecycle
swift
1. User Trigger (Siri/Shortcuts/Widget)
│
▼
2. Parameter Resolution
├── App Intents tanya parameter yang kurang (@Parameter dengan requestValueDialog)
├── EntityQuery.suggestedEntities() untuk auto-complete
└── disambiguation jika ada >1 match
│
▼
3. Confirmation (opsional)
└── requestConfirmation() jika intent destructive
│
▼
4. perform() — dieksekusi in-process
│
▼
5. IntentResult
├── Dialog (text Siri ucapkan)
├── View (custom SwiftUI untuk result)
└── Value (untuk chaining intent)
In-Process vs Extension
Berbeda dari SiriKit (separate extension process), App Intents berjalan in-process di dalam app itu sendiri. Ini berarti:
- Akses langsung ke semua service, model, dan data app
- Tidak perlu app group / shared container
- Memory footprint lebih efisien
- Tapi: app perlu diluncurkan (bisa di background) untuk perform()