Git Product home page Git Product logo

Comments (8)

mxcl avatar mxcl commented on May 28, 2024

I was indeed thinking about this too. Each local file would have to be a separate module. We could possibly make it so folders full of swift files were treated as modules.

from swift-sh.

mxcl avatar mxcl commented on May 28, 2024

My main concern is that at this point maybe you should just use SwiftPM, I know that the syntax for Package.swift is unpleasant nowadays… but still.

from swift-sh.

joscdk avatar joscdk commented on May 28, 2024

Yeah you might be right about using SwiftPM :)

Was thinking this could be a nice alternative to writing simple ruby scripts, where you just have a couple of files to build a small migration script, but might be the right way to do SwiftPM

from swift-sh.

mattt avatar mattt commented on May 28, 2024

As much as I appreciate the convenience of importing a local .swift file a la Ruby, I think the nature of Swift modules makes this approach untenable.

For one, I don't think the example above would actually work because Foobar and its members aren't declared with public access. Please don't take that as a personal knock, @joscdk --- I routinely run into problems caused by a missing public in my own code (especially code in the Sources directory for Xcode Playgrounds 😆). And I suspect many other folks would be flummoxed by this more often than not.

Aside from that, I worry about the logistics of managing external files as implicit modules. How do you detect changes? How do you reconcile namespace collisions and shadowed declarations? How do you handle dependency cycles? None of these are too hard individually, but in sum they amount to essentially recreating a good portion of package manager functionality.

from swift-sh.

joscdk avatar joscdk commented on May 28, 2024

@mattt yeah i see your point, this might be something that might be possible later as Swift matures as a language :)

from swift-sh.

mxcl avatar mxcl commented on May 28, 2024

SwiftPM is a better solution for this, and something like Xcode on top (though Xcode is not there yet) would make managing your modularity better.

from swift-sh.

davbeck avatar davbeck commented on May 28, 2024

SwiftPM probably is the right answer in most cases, but something that I ran into recently is a script used as part of a larger project (ie something that downloads resources that are then bundled into an app). In this case it makes sense to pull in a file or 2 from the primary project. For instance, the script may need to process some data and then write out a JSON file. The app of course is going to read the same file. In this case it makes sense for the app and the script to share the Codable models.

What if there was an include comment that pulled in single files to the same module?

// include Models.swift
Or
// include ../App/Models.swift

from swift-sh.

mxcl avatar mxcl commented on May 28, 2024

Yeah, my mind has changed. I have needed such things.

from swift-sh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.