Xcode 6:自动创建init函数?

时间:2021-08-07 18:19:49

Is there a way in Xcode 6 to generate the init function automatically?

Xcode 6中有自动生成init函数的方法吗?

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函数:

    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
    }

2 个解决方案

#1


3  

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

您可以对Xcode 8使用GenerateSwiftInit扩展—Xcode 8源代码扩展的概念证明;从当前选择生成一个Swift init。

#2


1  

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

不是为类,而是为struct,你会自动地得到一个像你正在寻找的那样的memberwise初始化器:苹果文档。

#1


3  

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

您可以对Xcode 8使用GenerateSwiftInit扩展—Xcode 8源代码扩展的概念证明;从当前选择生成一个Swift init。

#2


1  

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

不是为类,而是为struct,你会自动地得到一个像你正在寻找的那样的memberwise初始化器:苹果文档。