fahu
fahu

Reputation: 1531

Xcode 6: Create init function automatically?

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
    }

Upvotes: 13

Views: 4887

Answers (2)

Tram Nguyen
Tram Nguyen

Reputation: 473

You can use GenerateSwiftInit extension for Xcode 8 - Proof of concept for Xcode 8 source extensions; generate a Swift init from current selection

Upvotes: 6

Thorsten Karrer
Thorsten Karrer

Reputation: 1365

Not for classes, but for structs you will automatically get a memberwise initializer like the one you are looking for: Apple Docs

Upvotes: 1

Related Questions