图片转成 base64:
let image : UIImage =UIImage(named:"test.png")!
let imageData = UIImagePNGRepresentation(image)
let base64String = imageData!.base64EncodedStringWithOptions
(NSDataBase64EncodingOptions(rawValue:0))
base 转成图片:
let decodedData = NSData(base64EncodedString:base64String, options:NSDataBase64DecodingOptions())
let decodedimage = UIImage(data: decodedData!) as UIImage
字符串转 base64
let base64String ="字符串"
let data = base64String.dataUsingEncoding(NSUTF8StringEncoding)
let base64 = data?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.init(rawValue: 0)
base64 转 字符串
let decodedData:NSData? =NSData(base64EncodedString:"base64字符串", options: .IgnoreUnknownCharacters)
let decodedString = NSString(data: decodedData!, encoding: NSUTF8StringEncoding)!