Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
    }
like image 601
fahu Avatar asked Dec 18 '14 12:12

fahu


2 Answers

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

like image 147
Tram Nguyen Avatar answered Oct 22 '22 02:10

Tram Nguyen


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

like image 1
Thorsten Karrer Avatar answered Oct 22 '22 00:10

Thorsten Karrer