@@ -206,10 +206,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
206
206
207
207
/// Initializes a data object with the given Base64 encoded string.
208
208
public init ? ( base64Encoded base64String: String , options: Base64DecodingOptions = [ ] ) {
209
- guard var decodedBytes = base64String. utf8CString. withUnsafeBytes ( { buffer -> [ UInt8 ] ? in
210
- let bufferDroppingTerminatingNul = UnsafeRawBufferPointer ( rebasing: buffer. dropLast ( ) )
211
- return NSData . base64DecodeBytes ( bufferDroppingTerminatingNul, options: options)
212
- } ) else {
209
+ guard var decodedBytes = NSData . base64DecodeBytes ( base64String. utf8, options: options) else {
213
210
return nil
214
211
}
215
212
super. init ( )
@@ -218,8 +215,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
218
215
219
216
/// Initializes a data object with the given Base64 encoded data.
220
217
public init ? ( base64Encoded base64Data: Data , options: Base64DecodingOptions = [ ] ) {
221
- guard var decodedBytes = base64Data
222
- . withUnsafeBytes ( { NSData . base64DecodeBytes ( $0, options: options) } ) else {
218
+ guard var decodedBytes = NSData . base64DecodeBytes ( base64Data, options: options) else {
223
219
return nil
224
220
}
225
221
super. init ( )
@@ -671,7 +667,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
671
667
- parameter options: Options for handling invalid input
672
668
- returns: The decoded bytes.
673
669
*/
674
- private static func base64DecodeBytes( _ bytes: UnsafeRawBufferPointer , options: Base64DecodingOptions = [ ] ) -> [ UInt8 ] ? {
670
+ private static func base64DecodeBytes< T : Collection > ( _ bytes: T , options: Base64DecodingOptions = [ ] ) -> [ UInt8 ] ? where T . Element == UInt8 {
675
671
var decodedBytes = [ UInt8] ( )
676
672
decodedBytes. reserveCapacity ( ( bytes. count/ 3 ) * 2 )
677
673
0 commit comments