Company Switching
Guide to managing and switching between multiple companies in TheCompanyApp.
Overview
TheCompanyApp's multi-tenancy architecture allows a single user to:
Own multiple companies simultaneously
Participate in companies owned by others
Switch between companies instantly
Maintain separate context for each company
Each company is completely isolated — orders, inventory, contacts, and all data are scoped to the selected company.
Why Multiple Companies?
Common Use Cases
Consultants & Freelancers
Manage separate companies for different clients
Keep project data isolated
Switch context quickly during meetings
Franchise Owners
Operate multiple franchise locations as separate companies
Use same app for all locations
Corporate can share a master company with all franchisees
Multi-Business Owners
Run different businesses (e.g., retail + wholesale)
Separate accounting and inventory
Independent team members per business
Employee of Multiple Organizations
Participate in employer's company
Own a side business
Help friend's startup
All accessible from one app
Understanding Company Types
When you view your companies list, each falls into one of two categories:
Owned Companies (Private Store)
Characteristics:
You created this company
You are the owner (
isOwner = truein AccessControl)Data stored in Private Store (
TheCompanyApp.sqlite)Syncs to iCloud Private Database
Only on your devices unless you share it
Can invite team members (Business/Enterprise tier)
Full control over all settings
Indicator in UI: "Owner" badge or icon
Shared Companies (Shared Store)
Characteristics:
Created and shared by someone else
You accepted a share invitation
Data stored in Shared Store (
TheCompanyApp-shared.sqlite)Syncs to iCloud Shared Database
Visible to all participants
Limited control (based on AccessControl permissions)
Cannot delete company (only leave share)
Indicator in UI: "Participant" badge or shared icon
Company List View
Accessing the List
From Dashboard:
Tap company name in navigation bar
Company selector sheet appears
From Settings:
Navigate to Settings tab
Tap "Switch Company" or "Companies"
Company List UI
Each company row displays:
Company Logo (if set)
Company Name
Owner Badge (if you own it)
Tier (Free, Business, Enterprise)
Last Selected indicator (checkmark or highlight)
Sort Order:
Last accessed companies first (by timestamp)
Then alphabetically by name
Search:
Search bar to filter companies by name
Real-time filtering as you type
Switching Companies
Quick Switch
To switch to a different company:
Tap Company Selector (company name at top)
Tap Company you want to switch to
Sheet dismisses, app immediately loads new company context
What Happens Internally:
Effects:
All tabs reload with new company's data
Dashboard shows new company's metrics
Inventory shows new company's items
Orders show new company's orders
Contacts show new company's contacts
Persistence:
New selection saved to AppStorage
Remembered across app launches
Each device tracks its own selection independently
Switching from Login Screen
If you're at login screen and want to choose a different company:
Tap "< Back" or "Companies" button
Returns to companies list
Tap different company
New login screen appears for that company
Company Context
What Changes When Switching
Data Scope:
All fetch requests filter by new
companyIDPrevious company's data instantly hidden
New company's data loads from Core Data
User Context:
UserPass for new company loaded (separate credentials)
AccessControl for new company applied
Permissions and roles switch
CloudKit Store:
Owned company → reads from Private Store
Shared company → reads from Shared Store
App handles store resolution automatically
UI State:
Resets to default tab (Dashboard)
Clears any unsaved forms
Refreshes all list views
What Doesn't Change
App Settings:
Notification preferences (global)
UI theme/appearance
App-level configurations
iCloud Account:
Same Apple ID
Same CloudKit container
Device State:
Background sync continues for all companies
Notifications can arrive for any company
Managing Multiple Companies
Creating Additional Companies
You can create unlimited companies:
From Companies List:
Tap + "Create Company" button
Follow creation flow (see Create First Company)
Company Creation:
Each company gets unique
companyIDSeparate data scope
Independent tier/subscription
Own UserPass credentials
Joining Additional Companies
Accept invitations from others:
Receive Share Link (via Messages, Email, etc.)
Open Link (opens TheCompanyApp)
Accept Share (see Sharing Company)
Company Appears in companies list
Create UserPass when accessing first time
Deleting a Company
For Owned Companies:
Select the company
Navigate to Settings → Company Info
Scroll to bottom
Tap "Delete Company" (red text)
Confirm deletion (irreversible)
Effect:
All company data deleted locally
CloudKit records deleted from Private Database
If shared, participants lose access too
Cannot be undone
For Shared Companies (Participant):
Select the company
Navigate to Settings → Sharing
Tap "Leave Company"
Confirm
Effect:
Company removed from your device
Your access revoked
Owner can re-invite if needed
Performance Considerations
Switching Speed
Company switching is designed to be instant:
Optimization 1: No Network Calls
All data already synced locally
Switch happens purely in Core Data
No API calls or waiting
Optimization 2: Lazy Loading
Data fetched only when tab is viewed
@FetchRequestupdates automaticallyNo manual refresh needed
Optimization 3: In-Memory Store Reference
Memory Management
With many companies:
Only selected company's data active in memory
Background syncing lightweight (handles all companies)
No performance degradation with 10, 50, or 100 companies
Company Isolation
Data Isolation Guarantees
TheCompanyApp ensures absolute data isolation:
Query-Level Filtering:
No Cross-Company Queries:
Cannot accidentally fetch data from Company A while viewing Company B
Inventory, orders, contacts always scoped
Reports and analytics respect company boundary
Accidental Leakage Prevention:
insertCompanyItem()helper assigns objects to correct storeCompany-scoped views enforce
companyIDfilterRelationships validated against company
Syncing Across Devices
How Companies Sync
Owned Companies:
Created on Device A
Saved to Private Store
CloudKit syncs to Private Database
Device B (same Apple ID) pulls from Private Database
Appears in companies list on Device B
Shared Companies:
Owner shares company
Participant accepts on Device A
Saved to Shared Store
CloudKit syncs to Shared Database
Device B (participant's devices) pulls from Shared Database
Appears in companies list on Device B
Sync Timing:
Usually instant to 1 minute
Background sync continues even when inactive
Pull to refresh forces immediate check
Edge Cases
Same Company in Both Stores
Scenario: You own Company X, then someone else re-shares the same company name to you.
Reality: Different companies despite same name.
Each company has unique
companyIDTwo separate entities in your list
No conflict
Best Practice: Use unique company names to avoid confusion.
Owner Also Participant
Scenario: You own Company A, then accept a share for Company A from another device.
Current Behavior: Undefined (likely creates duplicate).
Recommendation: Don't share a company to yourself. Use single-owner model.
Switching While Saving
Scenario: Editing an order in Company A, switch to Company B before saving.
Result: Changes lost (not saved).
Mitigation: App should warn about unsaved changes (planned enhancement).
Troubleshooting
Company Not Appearing
Cause: Sync delay or sharing failure.
Solution:
Pull down to refresh companies list
Wait 1-2 minutes for sync
Check iCloud connection
Verify share was accepted correctly
Wrong Data Showing After Switch
Cause: Cached data or fetch request not updating.
Solution:
Pull down to refresh in affected tab
Force quit and restart app
Check that
@FetchRequestincludescompanyIDpredicate
Cannot Delete Company
Cause: Shared company (you're participant).
Solution:
Use "Leave Company" instead of "Delete"
Contact owner to transfer ownership first (if needed)
Lost Company After Update
Cause: CloudKit sync issue or data corruption.
Solution:
Check iCloud storage hasn't exceeded quota
Sign out and back in to iCloud
Reinstall app (data should restore from iCloud)
Technical Reference
Company Fetching
Company Classification
Switching Logic
Next: Sharing Company Related: Company Scoping, Private Store, Shared Store
Last updated