Giter Club home page Giter Club logo

objc2swift's Introduction

Objc2Swift.js npm version

Objc2Swift.js is an Objective-C to Swift converter written in JavaScript. (Live Demo)

This project is still highly experimenal and does not aim to provide human-less conversion. However, the most of Objective-C code can be converted to proper Swift code with less compilation errors.

Note: the author currently has no plan to support full features of Swift 3 or greater.

Features

  • Generate good-looking Swift 2.1 code from Objective-C code.
  • Full Objective-C parser which accepts large source code, not for toy-problem.
  • Preserve indents and comments in the original Objective-C code.
  • Reduce compilation errors with semantics analysis. See the Document for detail.
  • Command-line version supports #import delective with pre-compiled header cache.

Install

$ npm install -g objc2swift

Then, run the objc2swift command with --init option to setup the default configuration.

$ objc2swift --init ios

Note that the parameter ios means to setup objc2swift for using Xcode's iOS SDK. If you want to target other SDK, use osx, tvos or watchos.

Convert

Pass the target source file to the command. The conversion result will be written to the current directory with extension .swift.

$ objc2swift foo.m

The first conversion is very slow since there is no pre-compiled header cache. It will be speed-up later.

By default, the command searches user headers from the current directory and its subdirectories. To import more headers, use -I option can be used to specifiy include paths. For example,

$ objc2swift -I ~/git/myproject/ foo.m

The path specified by -I is recursively traversed.

Configuration

The default config path is ~/.objc2swift/config.json. A typical content of config.json is like following. If you want to add user header search path permanently instead of -I, add the path to includePaths array.

{
    "systemIncludePaths": [
        "${Xcode.app}/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks",
        "${Xcode.app}/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include",
        "${Xcode.app}/Contents/Developer/Platforms/iPhoneOS.platform/usr/lib/clang/3.5/include"
    ],
    "includePaths": []
}

How to Build

git clone https://github.com/okaxaki/objc2swift.git
cd objc2swift
npm install
npm run build

objc2swift's People

Contributors

okaxaki avatar harlanhaskins avatar mshibanami avatar dependabot[bot] 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.