无法使用类型为 '(UInt32, UnsafePointer, <Int8>UInt, [CChar], Int, UnsafeMutablePointer) 的参数列表调用'CCH



我将xCode和/或swift 1.0更新为1.2,但出现了很多错误,

我知道一些方法在 Swift 1.2 中更新/更改,因此我开始将整个项目更新到 swift 1.2。我被困在这一行上:

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result)

它抛出错误Cannot invoke 'CCHmac' with an argument list of type '(UInt32, UnsafePointer<Int8>, UInt, [CChar], Int, UnsafeMutablePointer<CUnsignedChar>)'

这是我的代码

.
.
.
 let str = cred.cStringUsingEncoding(NSUTF8StringEncoding)
        let strLen:Int = Int(cred.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
        let digestLen = Int(CC_SHA1_DIGEST_LENGTH)
        let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
        let objcKey = key as NSString
        let keyStr = Key.cStringUsingEncoding(NSUTF8StringEncoding)
        let keyLen:Int = Int(Key.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
        var st:NSString = dataFromHexadecimalString(Key)!
        let cKey = st.cStringUsingEncoding(NSUTF8StringEncoding)

        CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result)
.
.
.

注意:我从Uint to Int更改了keyLenstrLen,但仍然抛出相同的错误。

我解决了它,只是将strlen(cKey)转换为int,就像Int(strlen(cKey))

整行看起来像

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, Int(strlen(cKey)), str!, strLen, result)

最新更新