Comments (8)
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.
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.
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.
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.
@mattt yeah i see your point, this might be something that might be possible later as Swift matures as a language :)
from swift-sh.
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.
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.
Yeah, my mind has changed. I have needed such things.
from swift-sh.
Related Issues (20)
- Scripts don't run on M1 w/ Xcode 12.3 (x86 Homebrew) HOT 2
- Something odd about the 2.2.0 release brew record HOT 2
- Error: reference to member 'v11_1' cannot be resolved without a contextual type.macOS(.v11_1) HOT 3
- Change version to 11 HOT 1
- Fail to import when the package-name and repo-name are not identical HOT 1
- CI won't build linux with swift 5.1
- Brew complaining about outdated formula syntax HOT 1
- Error during installation: Invalid bottle tag symbol HOT 1
- Support scripts w/ `@main` HOT 1
- Dashes in product name breaks dependency resolving HOT 1
- Does not build for release with the Xcode 13 GM HOT 4
- PathKit dependency needs to be updated to 1.0.1 HOT 1
- Error reference to member `v12_1` cannot be resolved HOT 1
- Expose an option that prints the cached build directory? HOT 2
- CI and test failures update & PR links HOT 2
- Editing using `swift sh edit` eventually fails with "The file doesn't exist" HOT 2
- Configurable templates/context HOT 4
- Package not regenerated if you change the import reference HOT 1
- error: The operation couldn’t be completed. (NSPOSIXErrorDomain.13) HOT 6
- Missing support for async entry points HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-sh.