Better Self support with class funcs

Would be great to construct the current class in a class function like so

class func makeMeCheese() -> Self
{
return Self(type: .Cheddar);
}

···

--
 Wizard
james@supmenow.com
+44 7523 279 698

You can use `self` (and, to initialize, `self.init`) inside a class
function to refer to the class. A riff on your example here:
http://swiftstub.com/914697984/

Stephen

···

On Tue, Dec 15, 2015 at 6:56 AM, James Campbell via swift-evolution < swift-evolution@swift.org> wrote:

Would be great to construct the current class in a class function like so

class func makeMeCheese() -> Self
{
return Self(type: .Cheddar);
}

--
 Wizard
james@supmenow.com
+44 7523 279 698

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

When doing this with a UIViewController's init nibname method, I get this
error:

Constructing and object of class type 'Self' with a metatype value must use
a 'required' initialiser.

···

On Tue, Dec 15, 2015 at 3:11 PM, Stephen Celis <stephen.celis@gmail.com> wrote:

You can use `self` (and, to initialize, `self.init`) inside a class
function to refer to the class. A riff on your example here:
http://swiftstub.com/914697984/

Stephen

On Tue, Dec 15, 2015 at 6:56 AM, James Campbell via swift-evolution < > swift-evolution@swift.org> wrote:

Would be great to construct the current class in a class function like so

class func makeMeCheese() -> Self
{
return Self(type: .Cheddar);
}

--
 Wizard
james@supmenow.com
+44 7523 279 698

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
 Wizard
james@supmenow.com
+44 7523 279 698

Seems to be ok in a playground - just needs a required initialiser.

class Base {

  class func create() -> Self {
    return self.init()
  }

  required init() {
  }

}

class Derived : Base {
}

let a = Base.create()
let b = Derived.create()