Websync
示例
要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install
要求
安装
Websync 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'Websync'
如何使用
步骤 1:
您的 API URL
Websync.websynch_baseUrl = "https://your_api_url/"
创建 post 数据结构
struct pLogin: Codable {
var userName: String
var password: String
}
创建响应数据结构
struct rLogin: Codable {
var success: Bool
var access_token: String
}
步骤 2:
执行简单的 API 调用
import Websync
let user = pLogin(userName: "[email protected]", password: "raj123456")
Websync().post(postBody: user, methodName: "users", expected: rLogin.self) { response, error in
if response != nil {
let userResponse = response as! rLogin
print(userResponse.success)
} else {
// Error message here..
}
}
带有缓存和头的 API 调用
Websync().post(postBody: user, methodName: "users", expected: rLogin.self, header: ["auth":"12121"], cache: true) { response, error in
if response != nil {
let userResponse = response as! rLogin
print(userResponse.success)
} else {
// Error message here..
}
}
作者
chola,[email protected]
许可
Websync 在 MIT 许可下可用。请参阅 LICENSE 文件以获取更多信息。