Re: [swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-16 Thread Vladimir.S via swift-evolution
Yes, using the same example, you can make required init to be convenience init: class MyBase { required init (coder: Int) { } required init (frame: Int) { } } class MyClass : MyBase { let x:Int let y:String let z:Double private init(isCoder: Bool, _ xValue:

Re: [swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-16 Thread Charlie Monroe via swift-evolution
There's nothing stopping you from making init(frame:) and init?(coder:) convenience: public class ColorView: NSView { public required convenience init?(coder: NSCoder) { self.init(frame: CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0)) }

Re: [swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-16 Thread Jonathan Hull via swift-evolution
Good question/idea. The use case I have with this most often is -initWithCoder and some other init like -initWithFrame. I don’t think you can make those convenience inits. If there is a way to make that work though, I am all for it. The thing I do most often, when possible, is lazily set

Re: [swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-16 Thread Vladimir.S via swift-evolution
The question is if we can solve the problem with special private init() and convenience inits ? class MyBase { init () { } } class MyClass : MyBase { let x:Int let y:String let z:Double private init(_ xValue: Int, _ zValue: Double) { self.x = xValue

Re: [swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-16 Thread Jonathan Hull via swift-evolution
I don’t remember a proposal for that, but I would definitely support one. I use this pattern all the time (usually by initializing to a default value first), and it would be nice to have an explicit/safe way to handle it, (and to avoid waisting cycles creating an object I never use). Perhaps

Re: [swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-15 Thread Vladimir.S via swift-evolution
I believe there was(was?) already a suggestion to introduce special methods that could be called from initializers. IMO this is a better solution to the problem as you really should not call 'usual' instance method until the instance is fully instantiated(super.init() called in your case):

Re: [swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-15 Thread Karl Wagner via swift-evolution
Maybe there are several initialisers, with different ways of calculating 'y' depending on what you give it. Karl > > On Jun 15, 2016 at 2:26 PM, (mailto:char...@charliemonroe.net)> wrote: > > > > Is there a particular reason for not using lazy var here?

[swift-evolution] [Idea] Set variables to "_" in two-stage init; remove IUO

2016-06-15 Thread Karl via swift-evolution
Say you have the following code. There is a property on MyClass (‘y’) which is derived from other data via an instance method; Two-stage initialisation. class MySuperClass { init() {} } class MyClass : MySuperClass { let x : Int var y : String init(x: Int) {