NSData.base64EncodedStringWithOptions() Difficult to use in Swift with no options

Originator:justatheory
Number:rdar://17477565 Date Originated:2014-06-26
Status:Closed Resolved:
Product:Developer Tools Product Version:Version 6.0 (6A216f)
Classification:UI/Usability Reproducible:Always
 
Summary:
When I try to use base64EncodedStringWithOptions() in Swift, the static analyzer complains with "Cannot convert the expression's type "String!" to type NSBase64EncodingOptions".

Ah, I just finally figured it out. I had:

    let s = data.base64EncodedStringWithOptions(options: 0)

But it needed to be:

    let s = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.fromRaw(0)!)
 
Wow, really annoying. Would be great to have a `NSDataBase64EncodingOptions.noOptions` option. Or even better, un-deprecate the base64Encoding() method

Version:
Version 6.0 (6A216f)

Comments

From David Wheeler 16-Jul-2014 03:50 PM

Ah, that's much better, thanks! Suggest updating the docs for this method and other methods that take option-style enums. I was unaware that nil could be used for value types in Swift --- especially since the options argument is not marked as optional.

By justatheory at July 16, 2014, 10:51 p.m. (reply...)

From Apple Developer Relations 16-Jul-2014 08:54 AM

Engineering has determined that there are no plans to address this based on the following:

You need to use: data.base64EncodedStringWithOptions(nil)

Please let us know whether that helps you resolve the issue.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.

By justatheory at July 16, 2014, 10:51 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!