<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I think everyone possibly has different definitions of what ‘Swift-native rethinking’ could involve? My thoughts are, the Swift standard library is a base library of types and algorithms. There’s then a sister library that has serialisation, file reading and writing, and HTTP networking, dates, and more. At the moment that library is Foundation.</div><div class=""><br class=""></div><div class="">I think a good rule for Swift 3 has been, if some feature wasn’t already in, would it be added now if freshly proposed? Is it too far to ask what would a fresh take on Foundation look like?</div><div class=""><br class=""></div><div class="">There are certain things with Foundation that make it feel outdated or possibly less Swift-like:</div><div class="">- File references/paths are currently a part of NSURL. While this is 10 times better than the old NSString API, isn’t it still a bit odd, and a bit unfortunate to be bringing forward to Linux? There are a whole set of APIs of NSURL that only apply to files, and other another set that only apply to actual RFC 2396 URLs. Plus you have the NSFileManager APIs and the NSURLSession APIs, one for files and one for web URLs, and they both use the same type.</div><div class="">- Why does the library Alamofire have 16,000 stars given that it uses the relatively new API NSURLSession? Would a Swift Foundation aim to get a similar API?</div><div class="">- NSTask I think is a reasonable Objective-C API, but nowadays is verbose and throws exceptions:&nbsp;<a href="https://www.shinobicontrols.com/blog/scripting-in-swift" class="">https://www.shinobicontrols.com/blog/scripting-in-swift</a></div><div class="">- NSUserDefaults is designed to write to file storage by a single client as far as I know. i.e. would it be appropriate for a web server?</div><div class="">- Foundation is originally designed in a time before closures and before GCD. It’s had some additions to work those features in, but they don’t feel like Foundation has been based upon them.</div><div class="">- Having two types, the [NS]OutputStream class, and the&nbsp;OutputStreamable protocol, but they seemingly have nothing to do with each other? Why the designs of one or both change so that NSOutputStream could conform to&nbsp;OutputStreamable?</div><div class="">- APIs such as NSOperation that rely on key value coding and observation.</div><div class="">- NSOperationQueue, which back in its day added a nice Objective-C API over dispatch queues, but today could probably be achieved by use of protocol extensions and a smaller class that complement GCD?</div><div class="">- NSSortDescriptor, designed using key value coding.</div><div class=""><br class=""></div><div class="">Matthew Johnson raised the possibility of a “split between those who favor various libraries”. I take your point that “We are trying to avoid exactly the split you are concerned about.”</div><div class=""><br class=""></div><div class="">I think it is worth listing what Swift-native thinking includes. Here are my ideas based on what I’ve seen from the standard library and the community:</div><div class="">- Modular protocol oriented design</div><div class="">- Small focused APIs</div><div class="">- Elegant use of closures</div><div class="">- Explicit rejection of old conventions in order to find the best possible API</div><div class="">- Value types of course, which we have coming thanks to the effort here</div><div class="">- Ability to design with ‘micro’ value types, where objects would have been cumbersome or inefficient in Objective-C.</div><div class=""><br class=""></div><div class="">I have a feeling that for developers who start by learn Swift conventions and who know have exposure to other libraries and frameworks, that Foundation will feel a bit foreign to them. I feel there will be a split between library choices, as people go for something with more focused APIs that take advantage of Swift more. Is the plan for Foundation to still be a core part of Swift in the next 5+ years?</div><div class=""><br class=""></div><div class="">Foundation is a great API for the tools they had available with Objective-C and thoughtful naming and design. I feel if someone were to design an API given the current tools we have now, it would be very different.</div><div class=""><br class=""></div><div class="">I think modernising Foundation for Swift is a worthy effort, but seemingly making it the defacto sister library to the standard library feels a bit odd.</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 8 May 2016, at 2:53 AM, Tony Parker via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On May 7, 2016, at 6:06 AM, Jonathan Hull &lt;<a href="mailto:jhull@gbis.com" class="">jhull@gbis.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">-1 on this as well. &nbsp;How much does dropping NS really help things anyway? &nbsp;<div class=""><br class=""></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">All it does is force everyone to learn which things still have NS and which don’t. &nbsp;It also makes things much more difficult to search for… searching for NS_ gives the results you want quickly vs searching for anything in Swift foundation (e.g. Array -- which gives you a mixture of other programming languages and Taylor Swift gossip).</div><div class=""><br class=""></div><div class="">My proposal would be to keep NS for everything and then slowing making versions without the prefix, either by rewriting them to be better in Swift or simply aliasing the NS version. &nbsp;Once you have critical mass for useful things (around Swift 5~6), you can separate all the NSStuff out into their own NSFoundation which would be used only for backwards compatibility.</div><div class=""><br class=""></div><div class="">To the inevitable question: Wont having NS and Non-NS versions be confusing (especially if some are just aliases)? &nbsp;My answer is that it is less confusing than this proposal. There is a simple rule: Things without NS are always the new and preferred methods. Things with NS are there for compatibility and will continue to work the way they do in ObjectiveC (even if you have to import “NSFoundation” to get them instead of just “Foundation")</div><div class=""><br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">I think that this approach ends up with confusion as well. Maybe we end up with UserDefaults and NSUserDefaults? One is written in Swift and other is not, but what difference would that make to the caller? Swift itself is not written completely in Swift. Instead, let’s have one UserDefaults that has an API appropriate for Swift. You’ve seen some of that already with changes to the names of its methods (<a href="https://github.com/apple/swift/blob/master/apinotes/Foundation.apinotes#L575" class="">https://github.com/apple/swift/blob/master/apinotes/Foundation.apinotes#L575</a><span class="Apple-converted-space">&nbsp;</span>as one example, which takes advantage of overloading to simplify the API).</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">Side Note: I would also REALLY like to see a swift native improvement on NSAttributedString with native literal support.</div></div></div></blockquote><div class=""><br class=""></div><div class="">NSAttributedString was part of the value types proposal at the beginning but deferred for a few practical reasons. One reason is that I want additional existential support in the language first. AttributedString has the concept of a “longest effective run”, which is calculated by checking for equality between attributes. Attributed string should allow for AnyEquatableAndCopyable members of its attribute dictionary. A second problem is that the entire Cocoa text system (and hundreds of higher level APIs) are based on top of the NSString Index concept, which is hidden behind the unicodeScalar view of Swift.String. I would like a more unified story of how these two can interoperate before we revamp the base type.</div><div class=""><br class=""></div><div class="">Both of these are solvable, but they require time to collaborate between teams to decide what the right platform-wide approach is. We’ll do it, but it will not happen immediately.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><pre class="" style="white-space: pre-wrap; background-color: rgb(255, 255, 255);">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.</pre></blockquote><div class="">I would be curious to hear about your explorations (either in another thread or offlist)</div><div class=""><br class=""></div><div class="">I have written a couple of experimental versions of an improved Coding system for Swift. &nbsp;The key idea is to use closures to allow coding of arbitrarily complex nested types (e.g an array of tuples of Dictionaries: [(String, [String:Int])] ). &nbsp;It works pretty well, but unfortunately currently taxes the compiler to the point where it randomly crashes during compilation. &nbsp;I am waiting for the new generics stuff to come online before I explore further, since I believe that will dramatically simplify the code.</div></div><div class=""><br class=""></div><div class="">The other idea which I would like to see replicated is that it codes to an intermediate format which can then be transformed to/from binary data, XML, BSON (JSON + some representation for Binary Data) or some other format...</div><div class=""><br class=""></div><div class="">It also interoperates very well with existing NSCoding classes, which is an important feature.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">One thing to think about here is what the role of NSCoding is in the first place. It was designed to support archiving of UI objects to nib files. It has been pressed into service for all kinds of other interesting tasks since; UI state restoration, document formats, and IPC wire protocol, to name a few. It may be worthwhile to decide if these are really all the same use case or not. I’m honestly not sure yet. Some of these are very focused on dynamic behavior (that is, the object graph is not known in advance). For some, custom object types are really important (NSXPC takes full advantage of this, and is basically its reason for existence over the raw libxpc API). For others it is not (a raw document file of one million double values). Some of these have different performance requirements than others (archiving fast is important to IPC but unarchiving fast is important to loading nib files).&nbsp;</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- Tony</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>