I don't have 6.2 installed, but I don't think 6.3 is any different in this respect:
dataUsingEncoding returns an optional parameter, so you need to expand this.
NSDataBase64EncodingOptions.fromRaw been replaced by NSDataBase64EncodingOptions(rawValue:) . It is not surprising that this is not a bad initializer, so you do not need to deploy it.
But since NSData(base64EncodedString:) is a failover initializer, you need to deploy this.
Btw, all of these changes were suggested by Xcode migrator (click on the error message in the gutter and suggest a “fix”).
The final code rewritten to avoid a forced roll is as follows:
import Foundation let str = "iOS Developer Tips encoded in Base64" println("Original: \(str)") let utf8str = str.dataUsingEncoding(NSUTF8StringEncoding) if let base64Encoded = utf8str?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) { println("Encoded: \(base64Encoded)") if let base64Decoded = NSData(base64EncodedString: base64Encoded, options: NSDataBase64DecodingOptions(rawValue: 0)) .map({ NSString(data: $0, encoding: NSUTF8StringEncoding) }) {
(if you use Swift 1.2, you can use multiple if-let instead of a map)
Airspeed Velocity Mar 31 '15 at 10:06 2015-03-31 10:06
source share