Why is the method crossed out?

I defined a class like this:

internal class C {
    internal func method() -> Void {
        print("method called")
    }
}

If I declare the closure of this method, the method appears crossed out

let closure = C.init().meth
let closure2 = C.meth

The same thing happens if I use it in paranthesis autocasting \(...)

print("\(C.init().meth)")

Xcode examples:

example1 example2 enter image description here

+4
source share
1 answer

A breakthrough occurs because your function method()returns nothing. The contexts you are trying to execute (assignment and interpolation) expect a value, so the method returning Voidis not recommended there.

+5
source

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


All Articles