# DMRBaseLib **Repository Path**: riven-m/DMRBaseLib ## Basic Information - **Project Name**: DMRBaseLib - **Description**: 基础库,各种抽象类,抽象方法 - **Primary Language**: Swift - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-25 - **Last Updated**: 2026-11-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DMRBaseLib 可通过 Swift Package Manager 从源码编译的基础库,提供模型克隆、结果回调、 字节编解码、蓝牙广播数据访问、通用工具及任务调度。 ## 环境 - Swift 5.9+ / Xcode 15+ - iOS 13+、macOS 10.15+ - 包入口:仓库根目录的 `Package.swift`;product / module:`DMRBaseLib` ## 本地源码接入 Xcode → **File → Add Package Dependencies… → Add Local…**,选择本仓库根目录, 给需要使用的 target 添加 `DMRBaseLib` product。 其他 Swift Package 可使用相对路径。例如两个仓库位于同一目录: ```text GitSubmodule/ ├── DMRBaseLib/ │ └── Package.swift └── XWHAKit/ └── Package.swift ``` ```swift dependencies: [ .package(path: "../DMRBaseLib") ], targets: [ .target( name: "YourLibrary", dependencies: [ .product(name: "DMRBaseLib", package: "DMRBaseLib") ] ) ] ``` ## 远程源码接入 将仓库 URL 添加到 Xcode 的 Package Dependencies,或在清单中声明: ```swift .package( url: "https://codeup.aliyun.com/620db56c46d4d2ca636c19cd/DMRBaseLib-iOS.git", branch: "RefactorXWHAKit" ) ``` 该分支需要先包含本次 SPM 改造;私有仓库需配置访问凭据。远程仓库的包标识取自 URL 中的 `DMRBaseLib-iOS`,target 依赖写为: ```swift .product(name: "DMRBaseLib", package: "DMRBaseLib-iOS") ``` 当前 HandyJSON 使用 `master` 分支;若要将 DMRBaseLib 按语义化版本 tag 分发, 需要先将该分支依赖版本化,再让消费方使用 `from:` 指定 DMRBaseLib 的最低版本。 ## 三方依赖 | Product | URL | 版本规则 | |---|---|---| | `HandyJSON` | `https://gitee.com/riven-m/MMHandyJSON.git` | `master` 分支 | | `SmartCodable` | `https://github.com/iAmMccc/SmartCodable.git` | `7.0.0..<8.0.0` | | `SmartCodableMacro` | `https://gitee.com/riven-m/SmartCodableMacro.git` | `1.0.1..<2.0.0`(Up to Next Major Version) | 这些源码依赖由 SwiftPM 自动解析;`SmartCodableMacro` 会继续解析编译宏所需的 `swift-syntax`。原 Xcode 工程中的宏包也使用相同的版本规则。 宏包版本升级后,Xcode 会提示重新启用 `SmartCodableMacroPlugin`,启用后再构建。 ## 使用 ```swift import DMRBaseLib let bytes = UInt16(0x1234).bigEndianBytes // [0x12, 0x34] let value = ByteCodec.decode(bytes, as: UInt16.self) let mac = BluetoothMAC.parse("AABBCCDDEEFF", isInDataOrder: true) let canUpdate = Versioning.canUpdate(localVersion: "1.0", serverVersion: "1.1") ``` 接入时由宿主从源码编译本库,无需预先生成或拖入 `DMRBaseLib.framework`。 ## 验证 在仓库根运行: ```sh swift package resolve swift build swift test --filter ModelIntegrationTests ``` `ModelIntegrationTests` 验证消费方继承基础模型后的解析、宏展开与独立克隆。 现有测试也已纳入 SPM test target,可通过 `swift test` 运行完整测试。 当前完整测试中,`ByteCodecTests` 的 5 个 `decodePadded` 用例存在 12 条既有断言冲突: 部分期望高位补零 / 保留后缀,而源码使用尾部补零 / 保留前缀;同组其他用例也使用 尾部补零 / 保留前缀的期望。该问题需先统一这组接口和测试的语义。