Skip to content

Add NSUbiquitousKeyValueStore support#12

Merged
rizwankce merged 4 commits intomasterfrom
feature/nsubiquitouskeyvaluestore-support
May 25, 2025
Merged

Add NSUbiquitousKeyValueStore support#12
rizwankce merged 4 commits intomasterfrom
feature/nsubiquitouskeyvaluestore-support

Conversation

@rizwankce
Copy link
Copy Markdown
Owner

Adds functionality to store and retrieve Codable objects using NSUbiquitousKeyValueStore.

Key changes include:

  • Added ubiquitousKeyValueStore case to the StorageType enum.
  • Implemented save, retrieve, and clear logic for NSUbiquitousKeyValueStore in Storage.swift, using the provided filename as the key.
  • Added comprehensive unit tests in StorageTests.swift to cover the new storage type, including save, retrieve, clear, and non-existent data scenarios. Ensured test isolation with a tearDown method and usage of synchronize().
  • Updated README.md to reflect the new feature availability.

Adds functionality to store and retrieve Codable objects using NSUbiquitousKeyValueStore.

Key changes include:
- Added `ubiquitousKeyValueStore` case to the `StorageType` enum.
- Implemented save, retrieve, and clear logic for `NSUbiquitousKeyValueStore` in `Storage.swift`, using the provided filename as the key.
- Added comprehensive unit tests in `StorageTests.swift` to cover the new storage type, including save, retrieve, clear, and non-existent data scenarios. Ensured test isolation with a `tearDown` method and usage of `synchronize()`.
- Updated `README.md` to reflect the new feature availability.
rizwankce and others added 3 commits May 25, 2025 17:21
This commit addresses several test failures and underlying issues:

- **Storage.swift**:
  - Modified `UserDefaults` key generation to include the `filename`
    (e.g., `type.userDefaultsKey + ".\(filename)"`). This prevents
    `Storage` instances using `.userDefaults` with different filenames
    from overwriting each other's data.

- **Tests/LocationStorageTests.swift**:
  - Recreated this test file which was missing but present at runtime.
  - Implemented correct test logic for saving, retrieving, and clearing
    locations, particularly for `.userDefaults`.
  - Ensured proper test isolation with `setUp` and `tearDown` methods
    cleaning up specific `UserDefaults` keys.

- **Tests/StorageTests.swift**:
  - **UserDefaults tests**:
    - Modified `testOverwriteUserDefaultsData` to use a unique filename
      (`"overwriteTestUserDefaults"`) to prevent interference with
      `testSaveAndRetrieveUserDefaults`.
  - **NSUbiquitousKeyValueStore tests**:
    - Added short delays (`Thread.sleep(forTimeInterval: 0.2)`) after
      `save/clear` operations and `synchronize()` calls in
      `testSaveAndRetrieveUbiquitous` and `testClearUbiquitous`. This
      is to allow time for asynchronous iCloud key-value store
      operations to complete, addressing timing-related test failures.

These changes are intended to resolve all previously reported test failures.
Verification was blocked by an unrelated `apt-get update` issue.
Introduce KeyValueStorable protocol to generalize key-value store access.
Refactor Storage to use this protocol for NSUbiquitousKeyValueStore dependency
injection, enabling easier testing. Add MockKeyValueStore for unit tests and
update tests to use the mock instead of the real store.
@rizwankce rizwankce merged commit c958cd8 into master May 25, 2025
1 check passed
@rizwankce rizwankce deleted the feature/nsubiquitouskeyvaluestore-support branch May 25, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant