Import files into your Swift scripts!

Related tags

Guides swift scripting
Overview

Tests

Swiftmix logo

Swiftmix is a tool aimed to make better use of Swift scripts. Right now there is no decent way to import source files in scripts without using SPM. Swiftmix can solve this problem while requiring little to no modifications to existing scripts.

How to install

There are two ways to install Swiftmix:

  1. Clone the repo and run make install
  2. With Homebrew installed run brew install mrtokii/formulae/swiftmix

How it works

In short, you can now use swiftmix command instead of swift anywhere. There are no settings or parameters.

Swiftmix acts as a wrapper for swift interpreter. It scans for import directives and tries to find a file with corresponding name in current directory. Then Swiftmix inserts file's contents in place (only once, similar to Objective-C #import) and also deals with hashbangs inside imported files. Finally, with all the source code combined together it runs swift interpreter.

Examples

Consider having a file say.swift:

func say(_ str: String) {
    print("Say: \(str)")
}

And main script file myscript.swift:

#!/usr/bin/env swiftmix

import say.swift

say("Hello \(CommandLine.arguments[1])")

To run the main script:

$ swiftmix myscript.swift World
Say: Hello World

Alternatively, you can run the script directly, as it contains #!/usr/bin/env swiftmix line:

$ ./myscript.swift World
Say: Hello World
You might also like...
Airbnb's Swift Style Guide.

Airbnb Swift Style Guide Goals Following this style guide should: Make it easier to read and begin understanding unfamiliar code. Make code easier to

LinkedIn's Official Swift Style Guide

Swift Style Guide Make sure to read Apple's API Design Guidelines. Specifics from these guidelines + additional remarks are mentioned below. This guid

 The Official raywenderlich.com Swift Style Guide.
The Official raywenderlich.com Swift Style Guide.

The Official raywenderlich.com Swift Style Guide. Updated for Swift 5 This style guide is different from others you may see, because the focus is cent

A self-taught project to learn Swift.
A self-taught project to learn Swift.

30 Days of Swift Hi Community I am Allen Wang, a product designer and currently learning Swift. This project was totally inspired by Sam Lu's 100 Days

Explanations and samples about the Swift programming language
Explanations and samples about the Swift programming language

About Swift Contents Explanations and samples about: Swift Programming Language Swift Standard Library Target audience Developers familiar with object

A collection useful tips for the Swift language
A collection useful tips for the Swift language

SwiftTips The following is a collection of tips I find to be useful when working with the Swift language. More content is available on my Twitter acco

Swift Featured Projects in brain Mapping
Swift Featured Projects in brain Mapping

Swift 开源精选   自 2014年 WWDC 发布 Swift 语言以来,本项目 一直致力于将主流 Swift 中文学习、开发资源汇集于此,并且尽力紧密地跟踪、甄选优秀 Swift 开源项目,以方便开发者快速获得并使用。考虑 Swift 已经正式发布超过四年半(更无力管理维护海量的 Swift

A collection of Swift tips & tricks that I've shared on Twitter

⚠️ This list is no longer being updated. For my latest Swift tips, checkout the "Tips" section on Swift by Sundell. Swift tips & tricks ⚡️ One of the

An Xcode playground showcasing the new features in Swift 4.0.
An Xcode playground showcasing the new features in Swift 4.0.

What’s new in Swift 4 An Xcode playground showcasing the new features in Swift 4.0. As seen in the What’s New in Swift session at WWDC 2017. Written b

Owner
Vitaliy Salnikov
Software Engineer (iOS/Swift/Objective-C)
Vitaliy Salnikov
Tech blog about Put Generic Protocol as Variable Type. How Combine Publisher put into AnyPublisher

How to Put Generic Protocol as Variable Type Have you ever put a Protocol on a variable? I believe you do. The Delegate pattern is using a lot in UIKi

Tsungyu Yu 8 Aug 17, 2021
A simple class that wraps the process of saving or loading a struct or class into a single file

EZFile This is a simple class that wraps the process of saving or loading a stru

null 7 May 16, 2022
Jared Watson 0 Jan 8, 2022
A blog project where you can write your articles, upload photos, categorize them, and add them to your favorites

A blog project where you can write your articles, upload photos, categorize them, and add them to your favorites. The aim of the project is to learn the use of Core Data.

Cem 7 Mar 21, 2022
🌊 Let your code flow. Extension methods for fluent syntax in Swift.

Flow ?? Let your code flow. This library provides a bunch of extension methods for a better fluent syntax in Swift. This style is very useful for some

Alejandro Martínez 100 Nov 30, 2022
👨‍💻Watch the latest and greatest conference videos on your Mac

Conferences.digital is the best way to watch the latest and greatest videos from your favourite developer conferences for free on your Mac. Either sea

Timon Blask 768 Jan 4, 2023
SwiftUI module library for adding seasons theme animations to your app

HolidayThemes SwiftUI module library for adding seasons theme animations to your app. Requirements iOS 13.0+ Xcode 12.0+ Installation Swift Package Ma

null 2 Mar 7, 2022
Have you ever wanted to just throw your optional like a table?

JebStolem Have you ever wanted to just throw your optional like a table? Or mayb

Piotr Szadkowski 1 Feb 23, 2022
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022
Sweet-swift - Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper Functions and Common Utilities

Sweet Swift Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper F

Yanzhan Yang 2 Feb 6, 2022