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

时间:2015-04-23 07:42:40

标签: ios swift

我将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)
.
.
.

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

1 个答案:

答案 0 :(得分:1)

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

整行看起来像是

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