在 SPM 包中包含权利文件

问题描述 投票:0回答:1

我目前有一个

.testTarget
用于测试依赖 HealthKit 的包。为了测试我可以从 Apple HealthKit 写入和读取数据,我需要一个权利,否则我会得到:

"Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}

我的问题是:如何添加虚拟权利文件来绕过这种情况?或者也许还有另一种方法可以通过

.testTarget
来测试 HealthKit。

swift healthkit swift-package-manager
1个回答
0
投票

为了进行测试,您可以在内部模拟各种函数。通过正确设置包装器的保护级别,您可以仅针对

@testable
显示此属性。

public struct KeychainWrapper {
    struct SecFunctions {
        let itemCopyMatching: (_ query: CFDictionary, _ result: UnsafeMutablePointer<CFTypeRef?>?) -> OSStatus
        let itemDelete: (_ query: CFDictionary) -> OSStatus
        let itemAdd: (_ attributes: CFDictionary, _ result: UnsafeMutablePointer<CFTypeRef?>?) -> OSStatus
        let itemUpdate: (_ query: CFDictionary, _ attributesToUpdate: CFDictionary) -> OSStatus
    }

    var secFunctions = SecFunctions(
        itemCopyMatching: SecItemCopyMatching,
        itemDelete: SecItemDelete,
        itemAdd: SecItemAdd,
        itemUpdate: SecItemUpdate
    )
}
© www.soinside.com 2019 - 2024. All rights reserved.