Base64 Encoding/Decoding with Swift 2

后端 未结 1 457
长情又很酷
长情又很酷 2021-02-10 02:01

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

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

 let base64String = imageData!.base         


        
1条回答
  •  伪装坚强ぢ
    2021-02-10 02:28

    You should use .Encoding64CharacterLineLength instead of .allZeros:

    let imageData = UIImageJPEGRepresentation(firstImageView.image!, 0.2)
    
    let base64String = imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
    

    0 讨论(0)
提交回复
热议问题