extensionString{ varmd5:String!{ letstr=self.cStringUsingEncoding(NSUTF8StringEncoding) letstrLen=CC_LONG(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding)) letdigestLen=Int(CC_MD5_DIGEST_LENGTH) letresult=UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen) CC_MD5(str!,strLen,result) varhash=NSMutableString() foriin0..<digestLen{ hash.appendFormat("%02x",result[i]) } result.dealloc(digestLen) returnString(format:hashasString) } }
写代码的时候遇到的 正好记录下
需要
#import <CommonCrypto/CommonDigest.h>
原文链接:https://www.f2er.com/swift/326524.html