Add NSUbiquitousKeyValueStore support#12
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds functionality to store and retrieve Codable objects using NSUbiquitousKeyValueStore.
Key changes include:
ubiquitousKeyValueStorecase to theStorageTypeenum.NSUbiquitousKeyValueStoreinStorage.swift, using the provided filename as the key.StorageTests.swiftto cover the new storage type, including save, retrieve, clear, and non-existent data scenarios. Ensured test isolation with atearDownmethod and usage ofsynchronize().README.mdto reflect the new feature availability.