Ios 无法调用';CCHmac&x27;具有类型为';(UInt32,UnsafePointer<;Int8>;,UInt[CChar],Int,unsafemeutablepointer<;CUnsignedChar>;)

Ios 无法调用';CCHmac&x27;具有类型为';(UInt32,UnsafePointer<;Int8>;,UInt[CChar],Int,unsafemeutablepointer<;CUnsignedChar>;),ios,swift,Ios,Swift,我将xCode和/或swift 1.0更新为1.2,出现了很多错误 我知道一些方法在Swift 1.2中进行了更新/更改,因此我开始将整个项目更新为Swift 1.2。我被困在这条线上: CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result) 它抛出错误无法使用类型为“(UInt32,UnsafePointer,UInt,[CChar],Int,UnsafeMutablePointer)

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

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

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, strlen(cKey), str!, strLen, result)
它抛出错误
无法使用类型为“(UInt32,UnsafePointer,UInt,[CChar],Int,UnsafeMutablePointer)”的参数列表调用“CCHmac”

这是我的密码

.
.
.
 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)
.
.
.
。
.
.
让str=cred.cStringUsingEncoding(NSUTF8StringEncoding)
设strLen:Int=Int(cred.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
设digestLen=Int(CC\u SHA1\u DIGEST\u长度)
let result=unsafemeutablepointer.alloc(digestLen)
将objcKey=key设为NSString
让keyStr=Key.cStringUsingEncoding(NSUTF8StringEncoding)
让keyLen:Int=Int(Key.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
var st:NSString=dataFromHexadecimalString(Key)!
设cKey=st.cStringUsingEncoding(NSUTF8StringEncoding)
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1),cKey,strlen(cKey),str!,strlen,结果)
.
.
.

注意:我将
keyLen
strLen
Uint更改为Int
,但仍然抛出相同的错误。

我解决了它,只是将strLen(cKey)像
Int(strLen(cKey))一样转换为Int

整条线看起来像是

CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), cKey, Int(strlen(cKey)), str!, strLen, result)
比较一下。