Generates an init based on properties of a type.
Given a simple class Employee
:
class Employee {
let name: String
let id: Int
}
Employee
needs an init
method, which is largely boilerplate. This project includes an Xcode editor extension to generate the initializer. It matches declarations of the form:
var {name}: {Type}
let {name}: {Type}
Highlight the properties of Employee
and invoke the command by selecting Editor > Generate Swift Init > Generate Swift Init From Selection. The following code will be generated:
init(name: String, id: Int) {
self.name = name
self.id = id
}
Clone the repository. Run the GenerateSwiftInit target on your machine. You'll likely need to update code signing information.
A developer-signed mac app is included in the GenerateSwiftInit directory. It is compatible with macOS 10.12 and Xcode 8.
- Download and move it to your /Applications directory.
- Open System Preferences > Extensions
- Ensure the checkbox for GenerateSwiftInit is checked
- Restart Xcode