小编Pat*_*ush的帖子

在swiftui中2秒后推送视图

如何在没有任何交互的情况下在 swiftUI 中 x 秒后推送视图?

 NavigationView{
            .onAppear {
                DispatchQueue.main.asyncAfter(deadline: .now()+1.0) {
                    NavigationLink(destination: pageViewUi()) {
                        EmptyView()
                    }
                }
            }
}
Run Code Online (Sandbox Code Playgroud)

swift swiftui swiftui-navigationlink

2
推荐指数
1
解决办法
1370
查看次数

后台线程在主线程之前执行 ios swift

我想推送一个视图控制器,并希望其余任务在后台工作而不冻结 UI。但要么我的 UI 冻结,要么后台线程之前执行。附上我工作的一个小例子。

DispatchQueue.global(qos: .background).async {
        DispatchQueue.main.async {
            print("This is run on the main queue, after the previous code in outer block")
        }
        print("This is run on the background queue")
    }
Run Code Online (Sandbox Code Playgroud)

结果:

This is run on the background queue
This is run on the main queue, after the previous code in outer block
Run Code Online (Sandbox Code Playgroud)

主队列应该比后台线程先执行。

xcode multithreading ios swift ios13

0
推荐指数
1
解决办法
4081
查看次数