How to enable and interpret debugging logs for TheCompanyApp.
Core Data CloudKit Debugging
Xcode Scheme Arguments:
Product → Scheme → Edit Scheme...
Arguments Passed On Launch → Click "+"
-com.apple.CoreData.CloudKitDebug 3
-com.apple.CoreData.Logging.oslog 1
-com.apple.CoreData.ConcurrencyDebug 1
Levels:
3 = Info + Warnings + Errors (verbose)
Result: CloudKit sync logs appear in Xcode console.
CloudKit Container Logging
Additional Argument:
Logs: Container setup, account status, zone creation.
Network Logging
Environment Variable:
Edit Scheme → Run → Arguments tab
Environment Variables → Click "+"
Add:
Name: CFNETWORK_DIAGNOSTICS
Result: HTTP/HTTPS requests logged.
Reading Logs in Xcode
Run App from Xcode
Perform action (e.g., save company, accept share)
View logs in Debug Console (bottom panel)
Search Bar (bottom right of console):
Filter by "CloudKit": CloudKit
Filter by specific entity: Companies
Example Log:
Common Log Patterns
Successful Sync
Export (Upload):
Import (Download):
Network Unavailable:
Not Authenticated:
Quota Exceeded:
Share Creation:
Share Acceptance:
Enlistment:
Console.app (macOS)
Use Case: View logs from physical device or Simulator.
Connect device to Mac (or run Simulator)
Open Console.app (Applications → Utilities)
Filter Console Logs
Search Field:
Additional Filters:
Result: See all CloudKit-related logs for TheCompanyApp.
Console.app → Edit → Find → Filter Logs
Save as .txt or .log file
CloudKit Dashboard
Web Interface: https://icloud.developer.apple.com/dashboard
Select "TheCompanyApp" container
Choose Environment: Development or Production
Select zone (Private or Shared)
Browse records by type: CD_Companies, CD_InventoryItem, etc.
Useful for:
Monitoring Logs
View real-time CloudKit operations
Filter by operation type: Save, Fetch, QueryRecords
Example:
Debugging Crashes
Enable Crash Reporting
TestFlight: Automatic (testers opt-in).
Xcode: Crashes logged in Xcode console immediately.
Symbolicate Crash Reports
Get Crash Report:
Xcode → Window → Devices and Simulators
Select device → View Device Logs
Symbolication:
Drag .crash file to Xcode window
Xcode auto-symbolicates if dSYM available
View stack trace with function names
Manual Symbolication:
Replace 0x100000000 (load address) and 0x10000abcd (crash address) from crash report.
Common Crash Patterns
CloudKit Timeout:
Fix: Increase timeout, check network.
Core Data Concurrency:
Fix: Ensure context.perform { } used for background operations.
Interpreting Sync Issues
Symptom: Data Not Syncing
Check Logs For:
Export started → Export successful?
If failed → Error code (CKErrorDomain)
Network, authentication, quota errors?
Example Diagnosis:
→ Code 9 = Not authenticated → User not signed in to iCloud.
Symptom: Share Not Working
Check Logs For:
Creating share for record → Share created?
Share metadata fetched → Metadata valid?
Share accepted → Acceptance succeeded?
Enlisting records → All related data enlisted?
Example Diagnosis:
→ Enlistment failed → Check if related data has correct companyID.
Logging in Production
Disable Debug Logs: Remove Xcode scheme arguments for Release builds.
Implement Custom Logging:
Usage:
View in Console.app:
Instruments (Xcode):
Select template: Core Data
Record while performing actions
Identify Slow Queries: Look for fetches > 100ms.
Optimize: Add indexes, reduce fetch batch size, use predicates.
Related: Troubleshooting, Share Testing Checklist, Common Issues