斯威夫特与2 base64编码/解码 [英] Base64 Encoding/Decoding with Swift 2

查看:177
本文介绍了斯威夫特与2 base64编码/解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code与雨燕1.2 X上code 6.4正常工作:

My code was working well on Xcode 6.4 with Swift 1.2:

 var imageData = UIImageJPEGRepresentation(firstImageView.image!, 0.2)

 let base64String = imageData!.base64EncodedStringWithOptions(.allZeros)

在我搬到了X code 7和斯威夫特2出现以下错误:

Once I moved to Xcode 7 and Swift 2 the following error appeared:

EX pression的类型不明确没有更多的上下文

type of expression is ambiguous without more context

所以,我想:

let base64String = imageData!.base64EncodedStringWithOptions(options: NSDataBase64EncodingOptions.allZeros)

但有NSDataBase64EncodingOptions之间没有allZeros选项。

But there is no "allZeros" option among NSDataBase64EncodingOptions.

推荐答案

您应该使用 .Encoding64CharacterLineLength 而不是 .allZeros

let imageData = UIImageJPEGRepresentation(firstImageView.image!, 0.2)

let base64String = imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)

这篇关于斯威夫特与2 base64编码/解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆