Zephyr 🌬️

轻松地通过 iCloud 同步 UserDefaults

Swift Support Platform CocoaPods SwiftPM Compatible


关于

Zephyr 使用 NSUbiquitousKeyValueStore 通过 iCloud 同步特定的键和/或您的所有 UserDefaults

Zephyr 内置了监控功能,可以在后台同步特定键,随着键的改变而同步。

有关最新更新,请参阅 Releases 选项卡。

特性

安装说明

Swift 版本 分支名称 是否将继续接收更新?
5.1+ master
5.0 swift5.0
4.2 swift4.2
4.1 swift4.1
3.2 swift3.2
3.1 swift3.1

CocoaPods

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(url: "https://github.com/ArtSabintsev/Zephyr.git", majorVersion: 3)

手动

  1. 下载 Zephyr
  2. Zephyr.swift 复制到您的项目中。

设置

在 Xcode 中打开 iCloud 同步

在 Xcode 中,打开你的应用程序的项目/工作区文件

How to turn on iCloud Key Value Store Syncing

将 Zephyr 集成到你的应用中

在执行每次同步之前,Zephyr 会自动检查 UserDefaults 或 NSUbiquitousKeyValueStore 中的数据是否较新。 为了确保在连接到同一 iCloud 帐户的新设备上全新安装应用程序时不会发生覆盖,请确保在调用任何 Zephyr 方法之前注册您的 UserDefaults。 一种轻松实现此目的的方法是使用 UserDefaults Register API

同步所有 UserDefaults

Zephyr.sync()

同步特定的一个或多个键(可变参数选项)

Zephyr.sync(keys: "MyFirstKey", "MySecondKey", ...)

同步特定的一个或多个键(数组选项)

Zephyr.sync(keys: ["MyFirstKey", "MySecondKey"])

添加/删除用于后台监控的键(可变参数选项)

Zephyr.addKeysToBeMonitored(keys: "MyFirstKey", "MySecondKey", ...)
Zephyr.removeKeysFromBeingMonitored(keys: "MyFirstKey", "MySecondKey", ...)

添加/删除用于后台监控的键(数组选项)

Zephyr.addKeysToBeMonitored(keys: ["MyFirstKey", "MySecondKey"])
Zephyr.removeKeysFromBeingMonitored(keys: ["MyFirstKey", "MySecondKey"])

切换自动调用 NSUbiquitousKeyValueStore 的 Synchronization 方法

Zephyr.syncUbiquitousKeyValueStoreOnChange = true // Default
Zephyr.syncUbiquitousKeyValueStoreOnChange = false // Turns off instantaneous synchronization

调试日志记录

Zephyr.debugEnabled = true // Must be called before sync(_:)
Zephyr.sync()

使用特定的 UserDefaults 套件

if let suite = UserDefaults(suiteName: "group.com.example.app-name") {
  Zephyr.setUserDefaultsSuite(to: suite)
}

示例应用

请忽略示例应用程序,因为我没有在示例应用程序中添加任何演示代码。 它只存在于此存储库中以添加对 Carthage 的支持。

创建并维护者

Arthur Ariel Sabintsev