iOS Data and Device Services
Use this skill to keep app-owned data, Apple-managed records, external service state, device discovery, protocol trust, permissions, sync, and physical-world side effects distinct.
user intent -> authorization/capability -> typed local state -> external/service operation -> stale/error/conflict handling -> reviewable result -> retention/deletion
Read before acting
- Inspect the actual Xcode targets, deployment target, platforms, model containers, schema/migrations, iCloud containers, capabilities, entitlements, usage descriptions, background modes, network/accessory protocols, and persistence/privacy adapters.
- Read the data/persistence/sync route, location/maps/weather route, SwiftData/CloudKit deep dives, HealthKit deep dive, HomeKit/Bluetooth/Nearby deep dive, and contacts/calendar/network deep dives.
- Refresh the exact official pages in the Sources section before relying on an authorization status, capability, entitlement, iCloud/account behavior, protected-data rule, radio state, local-network prompt, weather freshness, or background-delivery claim.
Route workflow
- State the user-owned outcome and data class: private local record, synced record, selected HealthKit/Contacts/EventKit data, weather observation, HomeKit physical state, Bluetooth protocol, Nearby distance/direction, or local-network service.
- Choose the smallest storage/service route. Use SwiftData for structured local records, files for large user-owned data, Keychain for secrets, CloudKit only when cross-device/shared replication is needed, and the narrow system framework for protected data or device access. Do not add a backend or account to solve a local-first problem.
- Record the target matrix before implementation: platform/device family, permission and usage description, capability/entitlement, account/service state, model/schema version, data retention/deletion, supported accessory/protocol, network topology, and offline/manual fallback. Mark unknown availability as
to-verify.
- Separate state layers. Keep local persistence, migration, sync/account, authorization, discovery, trust/protocol, operation, freshness, conflict, and user review as separate states; never collapse them into
isConnected, isAuthorized, isSynced, or hasData.
- Draw the operation boundary:
intent -> check current state -> validate target/schema -> perform bounded operation -> reconcile callback/change -> persist projection -> show stale/error/retry/manual route. Make writes idempotent where a duplicate can cause harm.
- Define privacy and retention before querying or logging. Ask for the minimum type/field/date range, keep raw health/contact/location/home/radio data out of logs, minimize synced projections, explain what leaves the device, and provide app-side deletion/export/revocation behavior.
- Bound asynchronous work. Cancel queries, observations, sync batches, discovery scans, connections, ranging sessions, and retries when the feature no longer owns them. Finish observer/background callbacks, release radio sessions, and ignore stale callbacks after cancellation.
- Verify with fixtures first, then signed physical devices and real services/accessories. Record OS, device, account, authorization state, dataset, schema/environment, accessory firmware, network topology, timestamp, and observed latency/freshness; do not generalize one successful run.
Fast path
Write a truth-ownership table first: local, Apple system, remote, or derived. Implement one create/read/update/delete or observation slice with migration, conflict, and offline behavior, and add CloudKit, HealthKit, Contacts, or an accessory only when the table shows that service owns a required boundary.
Persistence and sync boundaries
- Keep a domain model independent of SwiftData/Core Data/CloudKit. Use SwiftData
ModelContainer/ModelContext and explicit schema/migration policy for local records; use ModelActor or an intentional isolation boundary for background persistence.
- Store large media/files outside record rows with stable references and coordinated deletion. Keep secrets in Keychain, not UserDefaults, logs, analytics, URLs, or ordinary model fields.
- CloudKit is replication with account, container, environment, network, quota, conflict, deletion, and schema state. It is not automatically the app’s only source of truth. Model iCloud unavailable, account changes, remote deletion, duplicate edits, server-record conflicts, schema migration, and partial/offline state.
- Treat a local write, successful save, change token, sync event, or last-known projection as evidence about one boundary only. Do not label it “synced,” “current,” “backed up,” or “shared” without the corresponding account/environment and reconciliation evidence.
- For reviewable AI-derived or external records, persist source identifiers, timestamps, model/algorithm version, provenance, review/edit state, and deletion relationship. Do not silently promote generated data into domain truth.
Protected personal data
- HealthKit authorization is fine-grained and privacy-preserving. A processed authorization request does not mean every type was granted; an empty read does not prove denial or absence of data. Query only needed types/ranges and preserve source/date/unit metadata.
- HealthKit observer updates indicate that matching data changed; follow with a bounded query, call the background completion handler, and handle limited history, deletions, account/device changes, and unavailable data. Never turn a missing sample or derived trend into a diagnosis, treatment, medical necessity, or guaranteed wellness claim.
- Contacts and EventKit are external user-owned stores. Choose picker/store authorization deliberately, request the minimum access, handle revoked/limited access, stale identifiers, user edits/deletions, duplicate events, time zones, and write confirmation. An imported contact or event is not permission to message, modify, or expose it elsewhere.
- WeatherKit results have service/entitlement, location, attribution, network, timestamp, forecast/historical scope, and cache/freshness state. Label location and observation time; do not present a forecast as a guarantee or a cached value as current.
Accessories, proximity, and local network
- HomeKit uses a shared Home database. Observe
HMHomeManager state, distinguish read from physical write, confirm actions that unlock/open/heat/alarm/monitor, and label last-known values. A callback or discovered accessory does not prove a safe or permanent physical effect.
- Core Bluetooth central and peripheral roles have different radio/protocol/background boundaries. Wait for
CBCentralManager/CBPeripheralManager state, scan only for supported service UUIDs, validate GATT services/characteristics and versioned payloads, stop scans, time out operations, and avoid unbounded reconnect loops.
- Nearby Interaction needs a session-specific peer/accessory configuration, discovery-token exchange, usage description, supported hardware, and session lifecycle. Distance/direction is relative framework output, not identity, location, trust, or safety proof. Use an authenticated/out-of-band exchange and a separate transport.
- Network/Bonjour discovery is not authentication. Request local-network access with the target declarations, model
NWBrowser/NWConnection ready/waiting/failed/cancelled states, authenticate the peer, secure sensitive traffic, handle network changes, and retain a manual pairing route where useful.
- Keep framework availability, discovered candidate, product trust, user selection, protocol compatibility, connection, and operation result distinct. Discovery never silently authorizes a physical side effect.
Non-negotiable safety and evidence rules
- Never present a local record, sync result, HealthKit value, contact/event, weather observation, accessory discovery, Bluetooth identifier, Nearby result, Bonjour name, or endpoint as current truth, identity, trust, medical validation, safety, or delivery proof without the separate evidence required by that domain.
- Never request a broad permission, protected data class, cloud account, accessory radio, local-network access, or telemetry path because it may be useful later. Tie every capability, entitlement, usage description, and retention rule to the stated feature.
- Treat external records, sync payloads, accessory messages, discovery results, weather responses, and local-network services as untrusted/stale. Validate IDs, dates, units, ranges, versions, signatures/authentication, payload sizes, and action targets before persistence or side effects.
- Never claim background delivery, sync timing, radio continuity, UWB support, accessory compatibility, weather freshness, or physical-world safety from a simulator, mock, fixture, preview, or one device.
- Preserve a useful local/manual path when permission, account, network, sensor, accessory, or service availability is missing. A fallback must not silently weaken security, privacy, paid access, or physical safety.
Deliverable
Produce a compact route note or implementation change containing:
- selected framework/storage/service and rejected alternatives;
- target/device, model/schema, account, permission, usage-description, capability, entitlement, accessory/protocol, network, privacy, and retention matrix;
- authorization/discovery/trust/operation/sync state machine with conflict, stale, cancellation, retry, manual fallback, and deletion behavior;
- source/date/unit/provenance and user-review policy for imported, synced, protected, or generated values;
- exact compile, fixture, signed physical-device, multi-device/service/accessory, privacy, performance, signing, and release evidence plan;
- remaining
to-verify gaps and claims deliberately not made.
For implementation, change only the requested target and directly related adapters/configuration. Do not add CloudKit, an account, a server, protected-data access, a radio permission, local-network access, background delivery, physical writes, analytics, or telemetry without a stated user-facing need and authorization.
Related routes and recipes
- Data, persistence, and sync
- Location, maps, and places
- SwiftData and local persistence
- CloudKit and sync
- HealthKit and sensitive data
- HomeKit, Bluetooth, and Nearby
- Contacts, calendar, and notifications
- WeatherKit and system data
- Persistence, local-first, and sync recipes
- Health, personal-data, and notification recipes
- HomeKit, Bluetooth, Nearby, and local-network recipes
- Permission, entitlement, and privacy checklist
- Build, device, and release checklist
Sources