Class initalizers
vihanb opened this issue · 6 comments
vihanb commented
Classes don't have initalizers, they'll need to support:
- Optional returns
init?
- Compilation
<name>.init.<params>
Validation and other problems are to be solved.
Examples:
public init?(a: T?) {
if a == T.b { return nil }
self.a = a
}
Additionally field initalization and super()
order checks should be implemented
somebody1234 commented
I don't think init
is a good idea, IMO we should make it like C# and make constructor name same as class name, plus return
s with a value aren't allowed in initializers
vihanb commented
@somebody1234 it is nullable intalizer so that why it is returning
vihanb commented
shit wrong issue :||||
taylorhansen commented
Wrong issue. :P
taylorhansen commented
So I take it that the constructor syntax would be something like this then:
public class A {
public init?(args) {
self(other args)
if(something bad) {
return nil
}
}
private init(args) {
super(other args)
do some stuff
}
}
vihanb commented
that looks good. (the init(args)
) would probably need to specify types but I assume you're using the function param list for initalizers anyway