SwiftInitializerGenerator - Xcode Source Code Extension to Generate Swift Initializers

Overview

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. Drag Swift Initializer Generator.app to your Applications folder

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

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

  10. 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.

Comments
  • "This target might include its own product" error when archiving

    I get this error whenever I archive (using Xcode 8). If I just build, I get #5:

    screen shot 2016-10-05 at 5 28 03 pm

    I tried disabling "Find Implicit Dependencies" in the scheme, and removing the explicit target dependency in the app target, but nothing helped :/

    opened by NachoSoto 6
  • Does not show option in the Editor menu

    Does not show option in the Editor menu

    As mentioned in #6

    Following README instructions it's still not showing up on the Editor menu in Xcode, despite multiple attempts, restarting Xcode, etc.

    question 
    opened by ed-mejia 5
  • Cannot Initialize `private` properties.

    Cannot Initialize `private` properties.

    The extension works great! However, when you try to initialize private properties, you get the following error:

    "The operation couldn't be completed. (Generate_Swift_Initializer.SourceEditorCommand.Error error 3)"

    opened by keyhoffman 4
  • Fix indentation handling

    Fix indentation handling

    The previous implementation did not support tab indentations or deeply nested types. Instead of using indentationWidth to pad the generated code, we deduce the current indentation depth from the first line in the selection and check if the user prefers tabs for the initializer body.

    This commit also inserts a new line between the variables and generated initializers, as this seems to be a common Swift design choice.

    opened by karlpuusepp 1
  • Doesn't appear in Extensions

    Doesn't appear in Extensions

    Followed instructions but nothing appears in System Preferences -> Extensions

    Any Clues? Thanks

    OS Version: 10.11.6 (15G1217) Xcode Version: 8.2.1 (8C1002)

    question 
    opened by normand1 1
  • "Embedded binary is not signed with the same certificate as the parent app" error when building

    Disclaimer: I'm 99.99% sure this issue has nothing to do with this repo, and it's just an(other) Xcode bug, I just figured I'd open this to see if other people run into the same thing.

    I was super excited to use this extension, but I'm getting the following error: screen shot 2016-10-05 at 5 17 07 pm

    I do have the same team in both targets: screen shot 2016-10-05 at 5 23 00 pm screen shot 2016-10-05 at 5 23 06 pm

    But of course Xcode is doing something wrong... or maybe I am? I hadn't used automatic signing yet, so maybe I'm doing something wrong.

    Note: I'm on Xcode 8.0

    opened by NachoSoto 1
  • Wrong example in the readme

    Wrong example in the readme

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

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

    b is an Int not a String

    opened by FlorianBasso 1
  • Doesn't work using some code density

    Doesn't work using some code density

    For struct using code density:

    public struct Advert: Codable {
        public let location: Location
        public let imageId, unitId, name: String
    
    }
    

    it gonna create initializer like this:

    public init(location: Location, imageId, unitId, name: String,

    which is not legal.

    pull request welcome 
    opened by Maxatma 1
  • Initialization appears outside of struct for some reason

    Initialization appears outside of struct for some reason

    
    public struct Some: Codable {
    	public var count: Int!
    	public var tag: String!
    }
    
        public init(count: Int!, tag: String!) {
            self.count = count
            self.tag = tag
        }
    
    

    As i understand, it should be like on animation, created inside struct.

    question 
    opened by o-zaporozhchenko 1
  • Does not work with playgrounds.

    Does not work with playgrounds.

    When run from a playground, I get the error Generate_Swift_Initializer.SIGError error 0. I assume this is SIGError.notSwiftLanguage. Maybe there is something special about the main source file in a playground...

    Seems to work great in regular projects.

    pull request welcome 
    opened by AtomicCat 3
Owner
Bouke Haarsma
Bouke Haarsma
XTextHandler - Xcode Source Editor Extension Tools (Xcode 8 Plugins)

Download Let's Swift! xTextHandler has been rewritten in Swift. The Objective-C version can be found in: https://github.com/cyanzhong/xTextHandler-obj

Ying Zhong (Inactive) 1.5k Sep 7, 2022
CleanClosureXcode - An Xcode Source Editor extension to clean the closure syntax.

Clean Closure - Xcode Source Editor Extension Clean Closure is a simple Xcode Source Editor Extension for Xcode 8. It parses each line of a file to si

Patrick Balestra 188 Jun 18, 2022
DocumenterXcode - Attempt to give a new life for VVDocumenter-Xcode as source editor extension.

DocumenterXcode Xcode source editor extension which helps you write documentation comment easier, for both Objective-C and Swift. This project is an a

Serhii Londar 34 Dec 17, 2022
Multiliner - An Xcode source extension to expand lengthy lines

Multiliner An Xcode source extension to expand lengthy lines. Super lightweight, 1 file. It expands long lines. That's it! Works with: Initializers Fu

Andrew Zheng 629 Jan 4, 2023
Import - Xcode extension for adding imports from anywhere in the code ☝️

Import ☝️ Xcode extension for adding imports from anywhere in the code. Now available on App Store Why? Because sometimes you are on 300th line of cod

Marko Hlebar 839 Nov 10, 2022
XShared - Xcode extension that allows you copying the code with special formatting quotes for social (Slack, Telegram)

This extension is for those who like to show code to the public ?? Xcode extension which allows you copying the code with special formatting quotes fo

Nikita Ermolenko 75 Jun 18, 2022
Xgist - Xcode extension to send code to GitHub's Gist

Xgist Xgist is a Xcode extension to send code to GitHub's Gist. The extension will send your code selection to Gist and automatically copy the Gist UR

Fernando Bunn 76 Jul 2, 2022
Comment-Spell-Checker - Xcode extension for spell checking and auto-correcting code comments.

Comment Spell Checker An Xcode Source Editor extension that runs spell check and auto correct on your code comments. Features Supports mutliple commen

Velislava Yanchina 157 Aug 28, 2022
Mark - Xcode extension for generating MARK comments.

Mark Xcode extension for automatic generation of MARK comments. Why? If you would like to organize your code with MARK comments, this will save you so

Velislava Yanchina 160 Dec 17, 2022
Nef-plugin - 🔌 an Xcode extension to use nef features easily

This project provides an extension for Xcode to integrate some nef features directly in the IDE. Using the core of nef, you can export snippets from y

Bow 188 Dec 23, 2022
This Xcode plugin shows Xcode app version in the Dock and App Switcher icon

Xcode Icon Version Tired of this Xcode icon always showing multiple times in your App Switch with no help watshoever as to which version you are curre

Stanislas Chevallier 94 Sep 11, 2022
Xcode plugin which help you write code faster.

MLAutoReplace Xcode plugin, Re-Intent, make you write code more quickly. Use a portion code of VVDocumenter-Xcode. ##Overview You can use shortcut key

molon 233 Sep 9, 2022
Snowonder - 🔮 Magical import declarations formatter for Xcode

Snowonder is Xcode Extension that adds some convenient formatting operations for Import Declarations. This extension is created with latest stable Swi

Alexey Karetski 104 Jan 4, 2023
XVim2 - Vim key-bindings for Xcode 9

XVim2 XVim2 is a Vim plugin for Xcode intending to offer a compelling Vim experience without the need to give up any Xcode features. Xcode 9 or above,

null 2.3k Jan 1, 2023
Xcode plugin to let you jump to GitHub History, Blame, PRs, Issues, Notifications of any GitHub repo with one shortcut.

Reveal-In-GitHub Xcode plugin to let you jump to GitHub History, Blame, PRs, Issues, Notifications of current repo in one second. My company work on G

lzwjava 257 May 17, 2022
Plugin for Xcode to integrate the Reveal App to your project automatic.

Reveal-Plugin-for-Xcode Plugin for Xcode to integrate the Reveal App to your project automatic(Without any modifications to your project). Please note

Eric 229 Jun 29, 2022
XcodeEquatableGenerator - Xcode 8 Source Code Extension will generate conformance to Swift Equatable protocol based on type and fields selection.

Depricated! There is not need for it at the moment as Swift compiler can do that for us ?? Swift Equatable Generator Xcode 8 Source Code Extension wil

null 191 Dec 10, 2022
XTextHandler - Xcode Source Editor Extension Tools (Xcode 8 Plugins)

Download Let's Swift! xTextHandler has been rewritten in Swift. The Objective-C version can be found in: https://github.com/cyanzhong/xTextHandler-obj

Ying Zhong (Inactive) 1.5k Sep 7, 2022
✨ Super sweet syntactic sugar for Swift initializers

Then ✨ Super sweet syntactic sugar for Swift initializers. At a Glance Initialize UILabel then set its properties. let label = UILabel().then { $0.t

Suyeol Jeon 4k Jan 4, 2023
And - Syntactic sugar for Swift initializers

And Syntactic sugar for Swift initializers Usage let label = UILabel().and { $0

donggyu 4 Jun 10, 2022