Shared Store
Detailed explanation of the Shared Store (Shared Database sync) in TheCompanyApp.
Purpose
The Shared Store syncs with CloudKit's Shared Database, enabling:
Multi-user access to company data
Real-time collaboration
Participant-level access control
What Lives in Shared Store
Entities
Companies (shared by other users)
All company-scoped data for shared companies:
InventoryItem, Orders, Dispatch, Tasks, ContactsData, etc.
NOT UserPass (always private)
When Created
Share Acceptance:
CloudKit Representation
Shared Database Zones:
One zone per CKShare (per company shared to user)
Zone name: Based on CKShare record ID
Record Types:
Same as Private Store (
CD_Companies,CD_InventoryItem, etc.)Records are copies shared from owner's Private Database
Multi-Device Sync (Participant)
Scenario: UserB accepts Company A share
Accept share on iPhone → CloudKit adds to Shared Database
Shared Database syncs to iPhone's Shared Store
iPad (same UserB Apple ID) polls Shared Database
iPad downloads Company A data → Saves to Shared Store on iPad
Company appears on both devices
Bi-Directional Sync
Participant Creates Order:
Owner Sees Change:
Owner's device polls Shared Database (for shares they created)
Downloads new order
Appears in owner's view
Note: Owner continues to access company via Private Store, but CloudKit mirrors changes between Private and Shared Databases for shared records.
Store Resolution
Helper Method:
Usage:
Access Permissions
Determined by:
CKShare Permissions: "Can Edit" vs "View Only" (set by owner)
AccessControl Entity: App-level permissions
Related: Private Store, Sharing Flow, Ownership Rules
Last updated