Synchronizing a local store to the cloud
At a glance
| Item | Summary |
|---|---|
| Purpose | Share data between a user’s devices and other iCloud users. |
| App architecture | A Swift sample with the source-visible chain AppDelegate → DetailViewController → InjectableCLLocationManager → AttachmentProvider → CoreData / CoreDataCloudKitDemo APIs. |
| Main patterns | View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks |
| Project style | 40 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── CoreDataCloudKitDemo/
│ ├── AppDelegate.swift
│ ├── Detail/
│ │ ├── DetailViewController+Sharing.swift
│ │ ├── DetailViewController.swift
│ │ └── AttachmentInteractionDelegate.swift
│ ├── Tag/
│ │ └── TagsCollectionView.swift
│ ├── Attachment/
│ │ └── FullImageViewController.swift
│ └── DataProvider/
│ ├── AttachmentProvider.swift
│ ├── Data Generators/
│ │ └── LargeDataGenerator.swift
│ ├── PostProvider.swift
│ └── TagProvider.swift
└── CoreDataCloudKitDemoUnitTests/
├── Shared/
│ └── CloudKitTestingSupport.swift
└── Test Cases/
└── TestMainViewController.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 7 project/configuration file(s) and 49 source declaration(s).
Overall architecture
flowchart LR
N1["AppDelegate"]
N2["DetailViewController"]
N3["InjectableCLLocationManager"]
N4["AttachmentProvider"]
N5["CoreData / CoreDataCloudKitDemo APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
CoreDataCloudKitDemo/AppDelegate.swift:13 — architecture anchor
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Core Data.
Ownership and state
classDiagram
AppDelegate o-- UIWindow : window
AppDelegate *-- CLLocationManager : locationManager
AppDelegate o-- CoreDataStack : coreDataStack
AppDelegate o-- AppDelegate : sharedAppDelegate
Ownership evidence
CoreDataCloudKitDemo/AppDelegate.swift:16 — stored dependency or nearest verified ownership anchor
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
// ...
var window: UIWindow?
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AppDelegate |
UIWindow (window) |
stores or receives | App/module collaborators |
AppDelegate |
CLLocationManager (locationManager) |
creates and retains | App/module collaborators |
AppDelegate |
CoreDataStack (coreDataStack) |
stores or receives | App/module collaborators |
AppDelegate |
AppDelegate (sharedAppDelegate) |
stores or receives | Initialized by the owner; the binding is immutable |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
CoreDataCloudKitDemo/Detail/DetailViewController+Sharing.swift:43 — representative type boundary
protocol SharingProvider {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate |
SharingProvider |
Defines a capability or collaboration contract | Concrete collaborators/imported frameworks |
AttachmentInteractionDelegate |
Defines a capability or collaboration contract | AnyObject |
PostInteractionDelegate |
Defines a capability or collaboration contract | AnyObject |
DetailViewController |
View lifecycle, callbacks, and feature coordination | SpinnerViewController, UICloudSharingControllerDelegate |
TagsCollectionView |
User-interface presentation and input forwarding | UICollectionView |
BlockBasedShareProvider |
Supplies a capability or framework resource | SharingProvider |
TestMainViewController |
View lifecycle, callbacks, and feature coordination | WindowBackedTestCase |
BlockFetchedResultsControllerDelegate |
Receives callback-driven events | NSObject, NSFetchedResultsControllerDelegate |
FullImageViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
The source explicitly defines local protocol relationships: InjectableUserIdentity → RenderableUserIdentity, InjectableShareParticipant → RenderableShareParticipant, InjectableShare → RenderableShare, BlockBasedShareProvider → SharingProvider, CoreDataStack → SharingProvider, CKUserIdentity → RenderableUserIdentity.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
thumbnailURL (CoreDataCloudKitDemo/DataProvider/Attachment+Image.swift:27) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
coordinateDeleting (CoreDataCloudKitDemo/DataProvider/Attachment+Image.swift:37) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
persistentContainer (CoreDataCloudKitDemo/DataProvider/AttachmentProvider.swift:12) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
_privatePersistentStore (CoreDataCloudKitDemo/DataProvider/CoreDataStack.swift:20) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
CoreDataCloudKitDemo/DataProvider/Attachment+Image.swift:27 — representative boundary
private func thumbnailURL() -> URL {
let fileName = uuid!.uuidString + ".thumbnail"
return CoreDataStack.attachmentFolder.appendingPathComponent(fileName)
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| View lifecycle, callbacks, and feature coordination | DetailViewController, FullImageViewController, MainViewController, SpinnerViewController |
The source’s Controller suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate, AttachmentInteractionDelegate, BlockFetchedResultsControllerDelegate, CLLocationManagerBlockDelegate |
The source’s Delegate suffix makes this role explicit. |
| Generates feature data or resources | LargeDataGenerator, TestLargeDataGenerator |
The source’s Generator suffix makes this role explicit. |
| Long-lived feature or framework coordination | InjectableCLLocationManager |
The source’s Manager suffix makes this role explicit. |
| Supplies a capability or framework resource | AttachmentProvider, BlockBasedShareProvider, PostProvider, SharingProvider |
The source’s Provider suffix makes this role explicit. |
| Transforms feature data or representations | ColorTransformer, SecureCLLocationTransformer |
The source’s Transformer suffix makes this role explicit. |
| User-interface presentation and input forwarding | TagsCollectionView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | CoreDataCloudKitDemo/Detail/DetailViewController.swift:13 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | CoreDataCloudKitDemoUnitTests/Shared/CloudKitTestingSupport.swift:13 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | CoreDataCloudKitDemo/AppDelegate.swift:14 |
Callback protocols invert event delivery back into the sample’s owner. |
Naming conventions
- Types: Controller: DetailViewController, FullImageViewController, MainViewController, SpinnerViewController, TagPickerViewController; Delegate: AppDelegate, AttachmentInteractionDelegate, BlockFetchedResultsControllerDelegate, CLLocationManagerBlockDelegate, PostInteractionDelegate; Generator: LargeDataGenerator, TestLargeDataGenerator; Manager: InjectableCLLocationManager; Provider: AttachmentProvider, BlockBasedShareProvider, PostProvider, SharingProvider, TagProvider; Transformer: ColorTransformer, SecureCLLocationTransformer; View: TagsCollectionView.
- Protocols:
SharingProvider,AttachmentInteractionDelegate,PostInteractionDelegate,RenderableUserIdentity,RenderableShareParticipant,RenderableShare. - Methods:
application,splitViewController,isShared,participants,shares,canEdit,canDelete,shareNoteAction. - Files:
CoreDataCloudKitDemo/AppDelegate.swift,CoreDataCloudKitDemo/Detail/DetailViewController.swift,CoreDataCloudKitDemo/Tag/TagsCollectionView.swift,CoreDataCloudKitDemoUnitTests/Test Cases/TestMainViewController.swift,CoreDataCloudKitDemo/Attachment/FullImageViewController.swift,CoreDataCloudKitDemo/DataProvider/AttachmentProvider.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches CoreData, UIKit, CoreDataCloudKitDemo, CloudKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
CoreDataCloudKitDemo/AppDelegate.swift |
AppDelegate |
CoreDataCloudKitDemo/Detail/DetailViewController+Sharing.swift |
RenderableUserIdentity, RenderableShareParticipant, RenderableShare, SharingProvider, func, func, func |
CoreDataCloudKitDemo/Detail/DetailViewController.swift |
DetailViewController, Section |
CoreDataCloudKitDemo/Tag/TagsCollectionView.swift |
TagsCollectionView, TagsFlowLayout |
CoreDataCloudKitDemoUnitTests/Shared/CloudKitTestingSupport.swift |
InjectableUserIdentity, func, InjectableShareParticipant, InjectableShare, BlockBasedShareProvider |
CoreDataCloudKitDemoUnitTests/Test Cases/TestMainViewController.swift |
TestMainViewController, BlockFetchedResultsControllerDelegate |
CoreDataCloudKitDemo/Attachment/FullImageViewController.swift |
FullImageViewController |
CoreDataCloudKitDemo/DataProvider/AttachmentProvider.swift |
AttachmentProvider |
CoreDataCloudKitDemo/DataProvider/Data Generators/LargeDataGenerator.swift |
LargeDataGenerator |
CoreDataCloudKitDemo/DataProvider/PostProvider.swift |
PostProvider |