Kingfisher withUnsafeBytes 错误处理

 

1.错误信息

withUnsafeBytes' is deprecated: use `withUnsafeBytes(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead

2.错误位置

Kingfisher withUnsafeBytes 错误处理_第1张图片

 

修改为

extension String: KingfisherCompatible { }

extension Kingfisher where Base == String {
    public var md5: String {
        if let data = base.data(using: .utf8, allowLossyConversion: true) {
        
      
            var message:[UInt8] = []
            data.withUnsafeBytes {
                message.append(contentsOf: $0)
            }
            let MD5Calculator = MD5(message)
            let MD5Data = MD5Calculator.calculate()

            var MD5String = String()
            for c in MD5Data {
                MD5String += String(format: "%02x", c)
            }
            return MD5String

        } else {
            return base
        }
    }
}

 

参考地址:

https://developer.apple.com/documentation/swift/array/2635991-withunsafebytes

你可能感兴趣的:(错误处理,iOS,swift)