Xcode Source Code Extension to Generate Swift Initializers
Switch branches/tags
Nothing to show
Clone or download
Bouke Merge pull request #13 from rerelease/master
The eternal indentation war continues…
Latest commit 2743373 Nov 8, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
SourceEditorExtension Fix indentation handling Nov 8, 2017
SwiftInitializerGenerator.xcodeproj Create unit test target Dec 21, 2016
SwiftInitializerGenerator Renamed applications and targets Sep 11, 2016
SwiftInitializerGeneratorTests Fix indentation handling Nov 8, 2017
docs GIF demo Sep 11, 2016
LICENSE Initial Commit Sep 11, 2016
README.md Xcode 8/9 Nov 3, 2017

README.md

Swift Initializer Generator

This Xcode Source Code Extension will generate a Swift initializer based on the lines you've selected. Handy if you made a struct public and now you have to provide the initializer implementation yourself.

Usage

Select the lines with the attributes that should be included in the initializer. See below; > is the start of the selection and < is the end of the selection.

struct MyStruct {
>    public var a: String
    public var b: Int<
}

Run the extension's "Generate Swift Initializer". Voila! The code above is modified to:

struct MyStruct {
    public var a: String
    public var b: Int
    public init(a: String, b: Int) {
        self.a = a
        self.b = b
    }
}

Demo

Installation

  1. On OS X 10.11 El Capitan, run the following command and restart your Mac:

     sudo /usr/libexec/xpccachectl
    
  2. Open SwiftInitializerGenerator.xcodeproj

  3. Enable target signing for both the Application and the Source Code Extension using your own developer ID

  4. Product > Archive

  5. Right click archive > Show in Finder

  6. Right click archive > Show Package Contents

  7. Open Products, Applications

  8. Drag Swift Initializer Generator.app to your Applications folder

  9. Run Swift Initializer Generator.app and exit again.

  10. Go to System Preferences -> Extensions -> Xcode Source Editor and enable the extension

  11. The menu-item should now be available from Xcode's Editor menu.

Known limitations

It will only parse attributes defined like (open|public|fileprivate|private|internal) [weak] (var|let) NAME: TYPE.