A closure that takes an Unsafe
parameter. If body
has a return value, that value is also used as the return value for the with
function.
あるクロージャ、それはUnsafe
バラメータを取ります。body
が戻り値を持つならば、その値はまたwith
関数の戻り値としても使われます。
withUnsafeCurrentTask(body:)
Availability
- iOS 13.0+
- iPadOS 13.0+
- macOS 10.15+
- Mac Catalyst 15.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 13.0+
Technology
- Swift Standard Library Swift標準ライブラリ
Declaration 宣言
func withUnsafeCurrentTask<T>(body: (UnsafeCurrentTask
?) throws -> T) rethrows -> T
Parameters パラメータ
body
Current Task Unsafe Current Task(body:) Current Task Unsafe Current Task(body:)
Return Value 戻り値
The return value, if any, of the body
closure.
body
クロージャの、もしあれば、戻り値。
Discussion 解説
If you call this function from the body of an asynchronous function, the unsafe task handle passed to the closure is always non-nil
because an asynchronous function always runs in the context of a task. However, if you call this function from the body of a synchronous function, and that function isn’t executing in the context of any task, the unsafe task handle is nil
.
Don’t store an unsafe task reference for use outside this method’s closure. Storing an unsafe reference doesn’t affect the task’s actual life cycle, and the behavior of accessing an unsafe task reference outside of the with
method’s closure isn’t defined. Instead, use the task
property of Unsafe
to access an instance of Task
that you can store long-term and interact with outside of the closure body.
代わりに、Unsafe
のtask
プロパティを使うことで、あなたが長期間格納することそしてクロージャ本体の外側で相互作用することが可能なTask
のインスタンスにアクセスしてください。