readSimDefaults function

Future<SimDefaultsResult> readSimDefaults(
  1. SimDefaultsReadInput input
)

Reads NSUserDefaults for a given bundle ID on the iOS simulator.

When input.key is null, reads all defaults for the bundle. When input.key is provided, reads that specific key.

Uses xcrun simctl spawn <device> defaults read <bundleId> [key].

Never throws; all error conditions are represented as sealed result cases.

Implementation

Future<SimDefaultsResult> readSimDefaults(SimDefaultsReadInput input) async {
  final device = await resolveSimulatorDevice();
  final bundleId = input.bundleId;

  final args = <String>[
    'spawn',
    device,
    'defaults',
    'read',
    bundleId,
    if (input.key != null) input.key!,
  ];

  final result = await runSimctlWithOutput(args);
  if (result.error != null) {
    return SimDefaultsFailed(result.error!);
  }
  return SimDefaultsReadSuccess(output: result.stdout!.trim());
}