Git Product home page Git Product logo

swiftscripting's Introduction

SwiftScripting

Utilities and samples to aid in using Swift with the Scripting Bridge

Generating Swift API for a Target Application

The scripting approach leveraged here is a Swift layer on top of the Scripting Bridge. Xcode ships with a pair of utilities, sdef and sdp, to aid Objective-C programmers in using the Scripting Bridge.

The sdef tool is used to extract the scripting definition from an application. It emits the scripting definition to standard output in XML format. The sdp tool can be used to convert the XML emitted by sdef to an Objective-C header file. This header file defines the scripting interface for a target application exposed to Objective-C by the Scripting Bridge.

When scripting applications using Swift, it is possible to leverage the same Objective-C headers emitted by sdp. However, due to the dynamically generated classes involved in realizing the Scripting Bridge interface, this approach can be cumbersome and forces the use of AnyObject types even in areas when more specific types are known to exist.

The approach here is to generate a set of Swift protocols based on the Objective-C header emitted by sdp. In most cases, the generated file can be used without modification. There are some corner cases where manual editing is required to correct issues or workaround bugs in the Swift compiler.

The basic recipe for generating the Swift protocols and enums for a fictitious application called App.app is as follows

  1. sdef /Applications/App.app > App.sdef
  2. sdp -fh --basename App App.sdef
  3. sbhc.py App.h
  4. sbsc.py App.sdef

Step 1 will create the App.sdef file in the current directory. Step 2 will create a file App.h, also in the current directory. Step 3 will create App.swift in the current directory. This is the primary file describing the scripting interface. The final step will create the file AppScripting.swift which contains an enum with values appropriate for class creation.

Note that the sbhc.py script leverages the Python bindings for libclang. You must install these bindings before running the script. You'll also need to install the Xcode command line tools (xcode-select --install.)

See https://majestysoftware.wordpress.com/2015/03/31/swift-scripting-part-1/ for part one of a four-part series that gives a bit of explanation related to SwiftScripting.

swiftscripting's People

Contributors

tingraldi avatar adam-rocska avatar demosdemon avatar sunsetsonwheels avatar

Watchers

James Cloos avatar

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.