Why is "init" not assigned?

I just read that a method initcannot be used as a value. Value:

var x = SomeClass.someClassFunction // ok
var y = SomeClass.init              // error

Example found in Language Link

Why should this be? Is this a way to ensure a language level that creates too dirty tricks due to some consistency, or maybe because it interferes with another function?

+4
source share
3 answers

Unlike Obj-C, where a function initcan be called several times without problems, there is actually no method called in Swift init.

init - , " ". MyClass() . myInstance.init(). , .

, .

var y = SomeClass.init

, .

+8

?

init - , .

, , init . , , , init, , .

0

Initializers have no return value. In order to appropriate something to him, he must be able to return something - and this is not so.

0
source

Source: https://habr.com/ru/post/1543122/


All Articles