Skip to content

tattn/SwiftRunner

Repository files navigation

SwiftRunner

Build Status Swift Package Manager compatible platforms License Swift Version

SwiftRunner can execute the string written in Swift on runtime.

How to use

Execute string as Swift

import SwiftRunner

let text   = "print(\"hello!\")"
let result = SwiftRunner.shared.run(string: text) // => hello!

switch result {
case .success(let stream):
    stream.output // => "hello!\n"

case .failure(let error): break
}

Features

  • Evaluate text written in Swift on runtime
  • Work on MacOS & Linux
  • Security measures

Waiting for your great pull requests :D

Try in Playground

This project contains a playground file. So you can try the features.

To try immediately, you can run the following:

$ cd <your working directory>
$ curl -sf https://raw.githubusercontent.com/tattn/SwiftRunner/master/scripts/try-playground.sh | sh -s

After building (⌘+B), you can try it :)

Requirements

  • Xcode 8.0+
  • Swift 3.0+

Installation

Swift Package Manager

import PackageDescription

let package = Package(
    name: "MyProject",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/tattn/SwiftRunner.git", majorVersion: 1)
    ]
)

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

SwiftRunner is released under the MIT license. See LICENSE for details.