Thursday, March 16, 2017

Foundation Swift Archival & Serialization Proposal

Itai Ferber et al. (via Swift Evolution):

Foundation’s current archival and serialization APIs (NSCoding, NSJSONSerialization, NSPropertyListSerialization, etc.), while fitting for the dynamism of Objective-C, do not always map optimally into Swift. This document lays out the design of an updated API that improves the developer experience of performing archival and serialization in Swift.

Specifically:

  • It aims to provide a solution for the archival of Swift struct and enum types
  • It aims to provide a more type-safe solution for serializing to external formats, such as JSON and plist

6 Comments RSS · Twitter

Right, let's replace open data exchange format with proprietary one.

Slava, I don't see anything about a new format. It's just a Swiftlier approach to working with existing serialization formats. The proposal's examples even use JSON.

Joshua Nozzi, this is the problem right there: "Foundation's current archival and serialization APIs (NSCoding, NSJSONSerialization, NSPropertyListSerialization, etc.), while fitting for the dynamism of Objective-C, do not always map optimally into Swift." Maybe the best way to get out of a hole is to stop digging?

The way it looks to me, this proposal is format-agnostic. It seems to me that this is completely extensible, and you can write your own components that convert to and from anything. It talks about integration with existing JSON tech in Foundation, but you could write your own for XML, yaml, a proprietary binary format, whatever, and any of your types that are encodable can be immediately stored in the format of your choosing.

> Maybe the best way to get out of a hole is to stop digging?

:-)

""Foundation's current archival and serialization APIs (NSCoding, NSJSONSerialization, NSPropertyListSerialization, etc.), while fitting for the dynamism of Objective-C, do not always map optimally into Swift."

Or more precisely:

"Swift's static nature does not fit well with the dynamism of the APIs it should be designed to interact well with"

Isn't this kind of useless if it doesn't work for enums with associated values? Just use one of the many libraries there are, or the protobuf stuff.

Leave a Comment