Is there a way in Xcode 6 to generate the init function automatically?
An example for better understanding:
I have these properties:
var name: String
var location: String
var date : NSDate
var host: String
var description: String
and I want to generate this init function automatically:
init (name: String, location: String, date: NSDate, host: String, description: String, eventReceived: NSDate) {
self.name = name;
self.location = location
self.date = date
self.host = host
self.description = description
}
You can use GenerateSwiftInit extension for Xcode 8 - Proof of concept for Xcode 8 source extensions; generate a Swift init from current selection
Not for classes, but for structs you will automatically get a memberwise initializer like the one you are looking for: Apple Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With