CocoaPods trunk is moving to be read-only. Read more on the blog, there are 6 months to go.

BmobSwiftSDK 1.0.2

BmobSwiftSDK 1.0.2

Maintained by Coder-tanpeng.



  • By
  • Bmob

BmobSwiftSDK

Swift Platform License CocoaPods

BmobSwiftSDK 是 Bmob 后端云的全新纯 Swift SDK,专为 Swift 现代并发模型设计,提供简洁、高效的云端数据管理能力。

特性

  • 纯 Swift 实现 - 无 Objective-C 桥接,完全适配 Swift 生态
  • async/await - 原生支持 Swift Concurrency,告别回调地狱
  • 模块化设计 - SPM/CocoaPods 按需集成(Core/Data/User/File/Cloud)
  • 加密传输 - 端到端 AES-128-CBC 加密,安全可靠
  • 类型安全 - BmobError 枚举 + throws 错误处理
  • 完整查询 - 条件/模糊/地理/统计/BQL 等查询能力
  • 实时数据 - WebSocket 连接 + AsyncStream 事件流

平台支持

平台 最低版本
iOS 15.0+
macOS 12.0+

安装

Swift Package Manager

在 Xcode 中,选择 File > Add Package Dependencies,输入:

https://github.com/bmob/BmobSwiftSDK

或直接在 Package.swift 中添加:

dependencies: [
    .package(url: "https://github.com/bmob/BmobSwiftSDK", from: "1.0.0")
]

CocoaPods

Podfile 中添加:

pod 'BmobSwiftSDK', '~> 1.0.0'

然后执行:

pod install

快速开始

1. 初始化

import BmobSDK

Bmob.initialize(appKey: "your-app-key")

2. 数据操作

// 创建对象
let gameScore = BmobObject(className: "GameScore")
gameScore["playerName"] = "Player1"
gameScore["score"] = 100

try await gameScore.save()

// 查询数据
let query = BmobQuery(className: "GameScore")
query.whereKey("playerName", equalTo: "Player1")
let results = try await query.find()

// 条件查询
let query = BmobQuery(className: "GameScore")
query.whereKey("score", greaterThan: 50)
query.order(byDescending: "score")
let topScores = try await query.find()

3. 用户认证

// 注册
let user = BmobUser()
user.username = "username"
user.password = "password"
try await user.signUp()

// 登录
let user = try await BmobUser.login(account: "username", password: "password")

// 退出登录
BmobUser.logout()

4. 文件上传

let file = BmobFile(localPath: "/path/to/image.jpg")
try await file.upload()
print("File URL: \(file.url ?? "")")

5. 云函数

// 调用云函数
let result = try await BmobCloud.run(function: "helloWorld", params: ["name": "Bmob"])

// 类型安全调用
struct HelloResponse: Decodable {
    let message: String
}
let response: HelloResponse = try await BmobCloud.run(function: "helloWorld")

文档

完整文档请访问:Bmob Swift SDK 文档

示例项目

coming soon...

版本历史

详见 CHANGELOG

开源协议

本项目基于 MIT 协议开源,详见 LICENSE

支持


Made with ❤️ by Bmob