Bridge NSData to stdlib type

Number:rdar://23010231 Date Originated:07-Oct-2015 10:45 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Swift 2.1
Classification:Enhancement Reproducible:Not Applicable
NSData lacks many stdlib features. In particular it is not a CollectionType and it is not a value type. This makes it somewhat cumbersome to use in Swift. It’s API is also at odds with usual stdlib conventions (using “length” rather than “count” for instance). 

There is no easy way to bridge an NSData to and from a stdlib type like [UInt8] without copying.

NSData should bridge to stdlib similar to how NSString and NSArray do. This could be as a “Data” (following NSArray -> Array) or something related to ManagedBuffer, or could be a [UInt8]. I believe I would prefer it to be a specific Data type. This would likely make it easier to deal with NSData subclasses (particularly dispatch_data). But it should bridge to something in stdlib.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!