When generating the NSManagedObject subclasses I noticed that Xcode uses NSData for binary data but in Chapter 8 the Core data tutorial uses Data, I have used both and can’t seem to find a good resource to confirm wether one is better over the other. What do you guys think?
Swift 3 introduced some new overlay value types for existing Foundation class types, such as Date for NSDate, Data for NSData and some more. The full list and details can be found in:
[SE-0069 Mutability and Foundation Value Types](https://github.com/apple/swift-evolution/blob/master/proposals/0069-swift-mutability-for-foundation.md)
Some of the reasons were
Provide proper value semantics,
let and var instead of mutable and immutable variants,
more "Swifty" APIs.
The new overlay types should provide all functionality that the corresponding Foundation type has, but if necessary, you can always cast from one type to the other.
When existing Foundation APIs are imported into Swift, the types are bridged automatically.
So to answer your question, in simple terms, NSData is a reference type, Data is a value type. A value type is lightweight, and for most use cases, would be a better solution for your needs, but functionality wise, there is no difference. Data is a “Swiftier” approach since it dropped the “NS” prefix. .