用于Swift 3中图像URL的Base64编码解码

时间:2016-12-07 03:02:58

标签: base64 swift3 xcode8

这是我编码的方式:

let url:NSURL = NSURL(string : pictURL)!
let imageData : NSData = NSData.init(contentsOf: url as URL)!
let str64 = imageData.base64EncodedData(options: .lineLength64Characters)
// next line my code to save in core data just ignore it

encoded data = 3286 bytes的值。我认为这是错误的

let pictEncoded = person.value(forKeyPath: "pictureurl") as! String

if let imageData = Data(base64Encoded: pictEncoded, options: .ignoreUnknownCharacters),
       let image = UIImage(data: imageData)
    {
        cell.imgView.image = image
    }

0 个答案:

没有答案