How to disable implicit Foundation imports?

I've been trying to knock out the dependencies my Swift programs have on corelibs-foundation recently. The issue I've run into with using these foundation-less replacements is that a number of core dependencies already import Foundation. So then what's the point of depending on one of these libraries when I already have to "pay" for Foundation & everyone already knows Foundation? (the specific libraries I've come up against are Soto & async-http-client)

For me that's definitely the major issue. I do think that replacements for major currency types like Date and maybe Data (though some Collection<UInt8> is pretty good for that) would really benefit from inclusion in the standard library just because they become so much more useful when everyone can agree on the same type. Just like Result used to be.

Specific feedback on swift-json

This library looks really awesome and if I ever do manage to banish Foundation from my server components, it will probably be what I use for JSON decoding.

Encoding is obviously an important feature to make it useful for replacing Foundation and I see you have that on your roadmap, which is great.

The other thing I think would really help (just my 2 cents!) would be a very simple entry point into the package. It's a small thing, but just decoding a Decodable type (where I think most Swift programmers would want to start with a package like this) requires seeing the following types:

  • JSON
  • Grammar
  • JSON.Rule
  • JSON.Rule.Root

If I were the author of this package, I would add a convenience API for what I think is the most popular use:

extension JSON {
    static func decode<Data: Collection, Decoded: Decodable>(_ data: Data, as: Decoded.Type) throws -> Decoded { ... }
}

So then your getting started example could be:

import JSON
struct MyType: Codable { var x: Int }

let input = #"{ "x": 1 }"#
let object = try JSON.decode(input.utf8, as: MyType.self)

Then the section after that could get into more advanced things like annotating error messages and fancy grammar things. Basically I think when the community & tools have such a heavy bias towards Foundation you have to make it as simple as possible to use an alternative.

The WebURL getting started section is extremely focused by comparison, even though that library has tons of complex functionality:

import WebURL

var url = WebURL("https://github.com/karwa/swift-url")!
url.scheme   // "https"
url.hostname // "github.com"
url.path     // "/karwa/swift-url"

url.pathComponents.removeLast(2)
// "https://github.com/"

url.pathComponents += ["apple", "swift"]
// "https://github.com/apple/swift"
9 Likes