Are screens closed when used in typed typed data?

In the following example, when a test closure is passed as a function parameter, it does not require @escaping. Does this mean that it is considered the closure of noescape? I am wondering if this will work to avoid heap allocation caused by escaping.

func test() {
    print("hello")
}

class b<T> {
    let closure: T
    // does not requires init(c: @escaping () -> Void)
    init(c: T) {
        self.closure = c
    }
}

var c = b(c: test)
+4
source share
2 answers

Does this mean that it is considered the closure of noescape?

, . , (init(c:) ) - , . @escaping, (.. , ) ( SE-0103).

, , , , . , , .

test. , , .

, - , , placeholder T, Swift thunk . , , ( Q & A).

, thunk (, ), , .

+2

, noescape?

.

, , , . , , . :

class Test {
    var closure: Any
    init(c: ()->Void) {
        self.closure = c //Error: Non-Ecaping parameter 'c' may only be called
    }
}

(T), , T . , , .

, , , .

: - . , , ", ".

+1

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


All Articles