我正在关注斯坦福大学的 CS193p 开发 iOS 应用程序在线课程。
它使用 Grand Central Dispatch (GCD) API 来演示多线程。但他们指出,
“自 WWDC 2021 起,GCD 已大部分被 Swift 新的内置异步 API 取代”。
因此,我想了解讲座中的代码在更新以使用这个新 API 后会是什么样子。
观看 Apple 的 WWDC 视频后,在我看来,
DispatchQueue.global(qos: .userInitiated).async { }这个新的异步 API 中被替换为Task { }或Task(priority: .userInitiated) {},但我不确定,被DispatchQueue.main.async { }替换为什么?
所以,我的问题是:
DispatchQueue.global(qos: .userInitiated).async { }已被替换为Task(priority: .userInitiated) {}DispatchQueue.main.async { }取代了?请帮忙,我想学习这个新的 async-await API。
以下是讲座中的代码,使用旧的 GCD API:
DispatchQueue.global(qos: .userInitiated).async {
let imageData = try? Data(contentsOf: url)
DispatchQueue.main.async { …Run Code Online (Sandbox Code Playgroud) 如何更改“LSMinimumSystemVersion 值”?\n
我收到了 Apple 发来的这封电子邮件:
\n\n亲爱的开发者,
\n我们发现您的应用最近交付时存在一个或多个问题,\n“MYAPPNAME”1.0。您的交付已成功,但您可能希望\n在下次交付时更正以下问题:
\nITMS-90899:Apple Silicon Mac 支持问题 - 该应用\n与提供的最低 macOS 版本 12.4 不兼容。它可以在 macOS 13.0 或更高版本上运行。请在新版本中指定\n13.0 或更高版本的 LSMinimumSystemVersion 值,或在 App\nStore Connect 中选择兼容版本。有关详细信息,请访问:\n https://help.apple.com/app-store-connect/#/dev2de8e790b
\n\xe2\x80\x99 更正问题后,您可以将新的二进制文件上传到 App\nStore Connect。
\n此致,
\n应用商店团队
\n
我收到以下错误:
无法将“Binding”类型的值分配给“String”类型
如何修复它?请帮忙。
struct TextFieldWithClear: View {
var title: String
@Binding var text: String
init(_ title: String, text: Binding<String>) {
self.title = title
self.text = $text // ERROR: Cannot assign value of type 'Binding<String>' to type 'String'
}
var body: some View {
HStack {
TextField("Title", text: $text)
Image(systemName: "xmark.circle.fill")
.onTapGesture { text = "" }
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图找出为什么我的小部件没有重新加载。我想entries从内部打印数组func getTimeline到控制台。
但是打印语句不会出现在控制台中。
如何让打印语句出现在控制台中?
添加.confirmationDialog到“取消”按钮后,当我单击“放弃更改”按钮时,我在控制台中收到以下消息:
[演示] 尝试在 < TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView : 0x104c07850> 上呈现 <SwiftUI.PlatformAlertController: 0x1038c8000 > (来自 < TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVVS_22_VariadicView_Children7ElementVS_24NavigationColumnModifier _: 0x104c1b2b0>),其视图不在窗口层次结构中。
这是什么意思?这是值得担心的事情,还是我可以忽略它?请帮忙
这是我的代码:
import SwiftUI
struct DetailView: View {
@Binding var scrum: DailyScrum
@State private var data = DailyScrum.Data()
@State private var isPresentingEditView = false
@State private var isShowingConfirmationDialog = false
var body: some View {
List {
Section(header: Text("Meeting Info")) {
NavigationLink(destination: MeetingView()) {
Label("Start meeting", systemImage: "timer")
.font(.headline)
.foregroundColor(.accentColor)
}
HStack {
Label("Length", systemImage: "clock")
Spacer()
Text("\(scrum.lengthInMinutes) minutes")
}
.accessibilityElement(children: .combine) …Run Code Online (Sandbox Code Playgroud) I want to share Core Data with the Widget. I guess I'll need to create App Group (I know how to do this). But how do I then share the Core Data database with the Widget?
If I wanna use Core Data in my app, I always just simply create a new Xcode project and check "Use Core Data", and I get this code (Persistence.swift - below), which hooks me up to a database.
How can I modify it, …
我正在学习斯坦福大学的 CS193p 开发 iOS 应用程序在线课程。\n我使用的是 Xcode 11.5。(我没有更新,因为这是课程讲师(Paul Heagarty)正在使用的版本。)
\n我正在尝试做作业3(设定游戏)。目前(为了避免重复代码)我正在尝试替换此片段:
\n VStack {\n ForEach(0..<numberOfShapes) { index in\n if self.card.shape == .diamond {\n ZStack {\n Diamond().fill()\n .opacity(self.opacity)\n Diamond().stroke(lineWidth: self.shapeEdgeLineWidth)\n }\n }\n if self.card.shape == .squiggle {\n ZStack {\n Rectangle().fill()\n Rectangle().stroke(lineWidth: self.shapeEdgeLineWidth)\n }\n }\n if self.card.shape == .oval {\n ZStack {\n Ellipse().fill()\n Ellipse().stroke(lineWidth: self.shapeEdgeLineWidth)\n }\n }\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n有了这个片段:
\n VStack {\n ForEach(0..<numberOfShapes) { index in\n ZStack {\n shape(self.card.shape).opacity(self.opacity)\n shape(self.card.shape).stroke(lineWidth: 2.5) // ERROR here: Value of type …Run Code Online (Sandbox Code Playgroud)