Effortlessly sync UserDefaults over iCloud
Zephyr has built in monitoring, allowing it to sync specific keys in the background as they change.
For the latest updates, refer to the Releases tab.
- ☑ CocoaPods and SwiftPM Support
- ☑ Syncs specific
UserDefaultskeys or all of your
- ☑ Background monitoring and synchronization between
- ☑ Detailed Logging
|Swift Version||Branch Name||Will Continue to Receive Updates?|
pod 'Zephyr' # Swift 5.1+ pod 'Zephyr', :git => 'https://github.com/ArtSabintsev/Zephyr.git', :branch => 'swift5.0' # Swift 5.0 pod 'Zephyr', :git => 'https://github.com/ArtSabintsev/Zephyr.git', :branch => 'swift4.2' # Swift 4.2 pod 'Zephyr', :git => 'https://github.com/ArtSabintsev/Zephyr.git', :branch => 'swift4.1' # Swift 4.1 pod 'Zephyr', :git => 'https://github.com/ArtSabintsev/Zephyr.git', :branch => 'swift3.2' # Swift 3.2 pod 'Zephyr', :git => 'https://github.com/ArtSabintsev/Zephyr.git', :branch => 'swift3.1' # Swift 3.1
Swift Package Manager
.Package(url: "https://github.com/ArtSabintsev/Zephyr.git", majorVersion: 3)
- Download Zephyr
Zephyr.swiftinto your project.
Turn on iCloud Sync in Xcode
In Xcode, open your app's project/workspace file:
- Click on your Project
- Click on one of your Targets
- Click on Capabilities
- Turn on iCloud syncing
- Under Services, make sure to check
- Repeat for all Targets (if necessary)
Integrate Zephyr into your App
Before performing each sync, Zephyr automatically checks to see if the data in UserDefaults or NSUbiquitousKeyValueStore is newer. To make sure there's no overwriting going on in a fresh installation of your app on a new device that's connected to the same iCloud account, make sure that your UserDefaults are registered BEFORE calling any of the Zephyr methods. One way to easily achieve this is by using the UserDefaults Register API.
Sync all UserDefaults
Sync a specific key or keys (Variadic Option)
Zephyr.sync(keys: "MyFirstKey", "MySecondKey", ...)
Sync a specific key or keys (Array Option)
Zephyr.sync(keys: ["MyFirstKey", "MySecondKey"])
Add/Remove Keys for Background Monitoring (Variadic Option)
Zephyr.addKeysToBeMonitored(keys: "MyFirstKey", "MySecondKey", ...) Zephyr.removeKeysFromBeingMonitored(keys: "MyFirstKey", "MySecondKey", ...)
Add/Remove Keys for Background Monitoring (Array Option)
Zephyr.addKeysToBeMonitored(keys: ["MyFirstKey", "MySecondKey"]) Zephyr.removeKeysFromBeingMonitored(keys: ["MyFirstKey", "MySecondKey"])
Toggle Automatic Calling of NSUbiquitousKeyValueStore's Synchronization method
Zephyr.syncUbiquitousKeyValueStoreOnChange = true // Default Zephyr.syncUbiquitousKeyValueStoreOnChange = false // Turns off instantaneous synchronization
Zephyr.debugEnabled = true // Must be called before sync(_:) Zephyr.sync()
Please ignore the Sample App as I did not add any demo code in the Sample App. It's only in this repo to add support for Carthage.
Created and maintained by
You may find interesting
Project Architecture Changes -
This is a version bump that only affects folks using SPM. This change results in less metadata files being brought into an installation now that the architecture of this repo has changed.
Fixed old bug on Initial Sync -
Synchronization is Hard
Thanks to the diligence of @aedificator-nl in (#47 & #48), a long standing bug was fixed that would early-exit an initial synchronization on the first attempted synchronization on a secondary device sharing the same iCloud account. In other words, syncing wouldn't occur right away until after the second device was had a subsequent synchronization attempt performed. I think this bug has been in the library for a long time, if not since the beginning, so I applaud @aedificator-nl for taking the time and diligence to find the nefarious line of code and working through the solution.
Updated Manifest Files -
Updated Package.swift and Podspec files to resolve https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/399.
Adds Swift 5.1 / Xcode 11 / iOS 13 Support -
This release adds support for Swift 5.1, iOS 13, and Xcode 11. Full updates here: #44
Faster Synchronization -
On working on a personal application of mine, I noticed that synchronization on a second/subsequent device did not work on that device's first launch of an application. After further investigation, I noticed that the
syncFromCloud method did not actually post a notification on completion. This has now been fixed.
Fixed Support for Swift Package Manager -
I fixed the
Package.swift so that it is now compatible with Xcode 11 and the latest Swift Package Manifest file (
Notifications firing on iCloud sync -
#36: Notifications will now be posted after an iCloud sync has occurred (thanks to @twostraws)
Swift 5.0 Support -
As of Zephyr v3.3.0, all future changes on
master will be done in Xcode 10.2 using Swift 5.0.
For those using Swift v4.2, please check out the
swift4.2 branch or version
3.2.0 - both point to the same commit hash.
Swift 4.2 Support -
As of Zephyr v3.2.0, all future changes on
master will be done in Xcode 10 using Swift 4.2.
For those using Swift v4.1.0, please check out the
swift4.1 branch or version
3.1.2 - both point to the same commit hash.
Minor optimizations -
- Minor swift optimizations
- Improved documentation.
Synchronized `monitoredKeys` -
monitoresKeysare now synchronized. (Thanks to @krzyzanowskim)
Custom UserDefaults synchronization and Swift 4.1 -
- Adds the ability to sync non-standard
- Thanks to @albertwujj in #28
- Adds Swift 4.1 Compatibility
Modernized Podspec file and Removed watchOS Support -
- Updated Podspec file.
.swift-versionfile, as it's been deprecated.
- Removed watchOS support since there are a few insurmountable issue (and because it seems no one was using or requesting this support).
Fixes Background Sync Issue (Swift 4 Bug) -
- Fixes #25. When converting to the codebase to Swift 4, the @objcMembers keyword was missing, so the KVO method was never being hit. This has been addressed.
Support for Swift 4 / iOS 11 / Xcode 9 -
Zephyr v3.0.0 adds support for Swift 4 / iOS 11 / Xcode 9. Only minor changes were made under-the-hood.
Moving forward, only support for the Swift 4 codebase (on master) will be maintained.
|Swift Version||Branch Name||Will Continue to Receive Updates?|
Fixed Carthage Support -
I broke Carthage support in v2.2.0. Fixed it in v2.2.3.
Jazzy Docs -
Added Jazzy Docs at http://sabintsev.com/Zephyr.
Updated Source Code -
Integrated Availability API to mark functions that were deprecated in v2.2.0
- Comments are now in the Apple preferred style.
- This is only a name change. The Functionality remains the same.
Note: These changes are for the master (Swift 3) branch only.
Version 2.0.0: Swift 3 Support -
I've updated the syntax from Swift 2.2 to Swift 3. Some refactoring was included.
Updated Tag -
Changed sample project for Carthage
Swift 2.2 -
Updated for Swift 2.2.
Added Swift Package manager Support
Added Carthage Support
Serialized queue changes that fixes an issue from v1.4.2 with regards to monitored keys not being synced To iCloud on observation.
- Zephyr now synchronously processes incoming and outgoing changes to your
monitoredKeyson a shared serial queue. (e.g., FIFO).
- Bugfix to
- Stylistic changes
Thanks to @vgritsenko for guidance in releasing this version.
Monitored keys are now synced to the cloud on a background thread.
syncUbiquitousStoreKeyValueStoreOnChange, which controls if
synchronizeimmediately. It is set to
trueby default to mimic previous behavior.
- Added notification handling for
Thanks to @davehakim for this update in PR #1.
Spelling is hard -
Fixed a spelling issue.
There was an issue involving monitored keys not being synced from iCloud. I wrongly assumed that
NSUbiquitousKeyValueStore could subscribe to key-value observation, just as
NSUserDefaults. I switched the
NSNotificationCenter paradigm and things seem to work.