Date
1 - 4 of 4
NSData base64Encoding vs. base64EncodedStringWithOptions
Alex Zavatone
Xcode 9.2, iOS 11.2, Objective-C the options are these starting on line 50 of NSData.h: typedef NS_OPTIONS(NSUInteger, NSDataBase64EncodingOptions) { // Use zero or one of the following to control the maximum line length after which a line ending is inserted. No line endings are inserted by default. NSDataBase64Encoding64CharacterLineLength = 1UL << 0, NSDataBase64Encoding76CharacterLineLength = 1UL << 1, // Use zero or more of the following to specify which kind of line ending is inserted. The default line ending is CR LF. NSDataBase64EncodingEndLineWithCarriageReturn = 1UL << 4, NSDataBase64EncodingEndLineWithLineFeed = 1UL << 5, } Questions - What did the deprecated base64Encoding do with the line endings? How long were lines and what happened at a line ending? The typedef for NSDataBase64EncodingOptions, 0 is given the text, NSDataBase64Encoding64CharacterLineLength, indicating that a line is 64 characters. The documentation for this states that “NSDataBase64Encoding64CharacterLineLength Set the maximum line length to 64 characters, after which a line ending is inserted.”. The comment on line 52 for NSDataBase64Encoding64CharacterLineLength states something different. // Use zero or one of the following to control the maximum line length after which a line ending is inserted. No line endings are inserted by default. It states that a line ending is inserted and no line endings are inserted by default. - Which is the default value, 0? nil? I’d expect that it is 0, but the documentation for 0 states that a line ending is inserted and that no line endings are inserted by default. If 0 is the default, how is this possible? - What happens for NSDataBase64Encoding76CharacterLineLength? Can someone please clarify what Apple’s confusing documentation doesn’t? Thank you, Alex Zavatone |
|
Alex Zavatone
From the docs: Discussion By default, no line endings are inserted. If you specify one of the line length options (NSDataBase64Encoding64CharacterLineLength or NSDataBase64Encoding76CharacterLineLength) but don’t specify the kind of line ending to insert, the default line ending is Carriage Return + Line Feed. Does this mean that we need to pass in nil as an option to obtain the default case? Alex Zavatone
|
|
On Apr 13, 2018, at 9:39 AM, Alex Zavatone <zav@...> wrote:I haven't tested this, but I would imagine that it produced no line endings at all (i.e., a string containing only base64 alphabet). The typedef for NSDataBase64EncodingOptions, 0 is given the text, NSDataBase64Encoding64CharacterLineLength, indicating that a line is 64 characters.No it doesn't: NSDataBase64Encoding64CharacterLineLength = 1UL << 0,The enum defines a bit mask. The above declaration contains a shift. It equals 1. -ben |
|
Alex Zavatone
On Apr 13, 2018, at 12:05 PM, Ben Kennedy <ben-groups@...> wrote:DOH. I think it’s time for me to update my glasses prescription.On Apr 13, 2018, at 9:39 AM, Alex Zavatone <zav@...> wrote:I haven't tested this, but I would imagine that it produced no line endings at all (i.e., a string containing only base64 alphabet). Thank you. |
|