[swift-evolution] Dropping NS Prefix in Foundation
cocoadev at charlessoft.com
Sat May 7 12:14:49 CDT 2016
On May 6, 2016, at 5:06 PM, Tony Parker via swift-evolution <swift-evolution at swift.org> wrote:
> Hi David,
>> On May 6, 2016, at 2:56 PM, David Waite <david at alkaline-solutions.com <mailto:david at alkaline-solutions.com>> wrote:
>> -1 On the group as-is. I do not believe all of these classes have the behavior that would be expected if ‘foundation’ were a from-scratch foundational library for Swift (as it exists on non Apple platforms). This will lock Swift into an evolutionary path for these types going forward.
>> There is enough here that I will just pick one example to focus on - NSCoding/NSCoder, and elements I would suspect from such a from-scratch design
>> - Coding would incorporate SecureCoding into its design (I did not see NSSecureCoding even on the list of protocols to get the prefix dropped)
> SecureCoding should be on the list actually.
>> - Archiver/Unarchiver would not exist; we would only have keyed versions
>> - Coder would be a split in half to Coder and Decoder
>> - Coder and Decoder would be protocols
>> - The Coder protocol might have a single method, encode(value:Coding, forKey:String)
>> - The Decoder protocol might single method, <T:Coding> decode(type:T.Type, forKey: String) -> T?
>> - Compiler generation of a default Coding implementation
>> And possibly more such as:
>> - Add Coders limited to trees of objects vs graphs, to allow the Coder/Decoder protocols to be used for more intuitive JSON/XML representations
>> - Custom/specific assignment operator for Decoder to capture desired type without requiring said type to be specified in decode(type:forKey:) calls
> There’s no question that we can improve Coding for Swift. I have actually explored this area quite a bit although I don’t have anything planned for Swift 3 at this time.
> The general point is though, that we can do it by extending Foundation in that direction over time. In fact, keyed archiving is the perfect example of how we were able to do just that in the past in Objective-C. NSArchiver already existed and served a particular purpose, so we extended the concept into NSKeyedArchiver using the facilities available to us at the time.
> It’s not a goal to rewrite Foundation from scratch in Swift. All Swift apps that are running out there today are in fact using a combination of Swift, Objective-C, C, C++, various flavors of assembly, and more. The goal is to present the existing API of Foundation in a way that fits in with the language today while allowing us to iteratively improve it over time.
> - Tony
The trouble with (NS)Coding is that due to the legacy cruft, you have to consider the possibility that the coder sent to your -initWithCoder: and similar methods could be insecure coders and/or non-keyed coders, and either support each branch (making your method three times as long as it needs to be), or add code to error out if you get one of the legacy coder types.
A brand new coding mechanism, built from scratch, would be kind of refreshing in that regard.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution