CtrlK
BlogDocsLog inGet started
Tessl Logo

thiennc-tesoglobal/ios-skills

Community-maintained Agent Skills for complete Swift and Apple-platform app delivery.

72

Quality

90%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Medium

Suggest reviewing before use

Overview
Quality
Evals
Security
Files

dockkit-errors-and-testing.mdskills/dockkit/references/

DockKit Error Handling and Testing Patterns

Use this reference when handling DockKit error states, rate limit backoffs, and writing unit tests with mock dock accessories in Swift.

Contents

  • Error Handling
  • Testing Patterns

Error Handling

DockKitError Cases

ErrorCauseRecovery
.notConnectedNo accessory is dockedWait for .docked state
.notSupportedOperation not availableCheck framework availability
.notSupportedByDeviceDevice lacks DockKit supportDegrade gracefully
.invalidParameterBad input valueValidate before calling
.cameraTCCMissingCamera terms or authorization missingExplain the camera access requirement
.frameRateTooHightrack() exceeds 30 fps, or animate / setOrientation exceeds 2 calls per secondReduce call frequency
.frameRateTooLowObservations below 10 fpsIncrease call frequency
.noSubjectFoundNo trackable subject detectedShow user guidance

Guarding API Calls

func safeTrack(
    observations: [DockAccessory.Observation],
    cameraInfo: DockAccessory.CameraInformation,
    accessory: DockAccessory
) async {
    do {
        try await accessory.track(observations, cameraInformation: cameraInfo)
    } catch let error as DockKitError {
        switch error {
        case .notConnected:
            // Accessory disconnected, stop tracking loop
            break
        case .frameRateTooHigh:
            // Throttle observation delivery
            break
        case .frameRateTooLow:
            // Speed up frame processing
            break
        case .noSubjectFound:
            // No subject in observations, continue
            break
        default:
            break
        }
    } catch {
        // Unexpected error
    }
}

Testing Patterns

Conditional DockKit Integration

DockKit requires physical hardware. Use conditional compilation or runtime checks to keep the app functional without a dock:

#if canImport(DockKit)
import DockKit
#endif

final class DockController {
    var isDockKitAvailable: Bool {
        #if canImport(DockKit)
        return true
        #else
        return false
        #endif
    }

    func startTracking() async {
        #if canImport(DockKit)
        do {
            for await stateChange in try DockAccessoryManager.shared.accessoryStateChanges {
                // Handle state changes
            }
        } catch {
            // DockKit not available on this device
        }
        #endif
    }
}

Mock Accessory for UI Development

When building UI without hardware, mock the accessory state:

@Observable
final class MockDockViewModel {
    var isConnected = true
    var accessoryName: String? = "Mock DockKit Stand"
    var batteryLevel: Double? = 0.75
    var isCharging = false
    var trackingMode = "System"

    // Use in SwiftUI previews
    func simulateDisconnect() {
        isConnected = false
        accessoryName = nil
        batteryLevel = nil
    }
}

skills

.mcp.json

README.md

tile.json