我的第一个视图可以从 API 请求中获取所有数据,然后打开第二个视图更改 API 请求数据,它崩溃了。
下面是错误
Fatal error: No ObservableObject of type NetworkManager found.
A View.environmentObject(_:) for NetworkManager may be missing as an ancestor of this view.: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Monoceros_Sim/Monoceros-39.3/Core/EnvironmentObject.swift, line 55
2019-11-07 12:00:01.961425-0800 EarthQuake[73703:5913116] Fatal error: No ObservableObject of type NetworkManager found.
A View.environmentObject(_:) for NetworkManager may be missing as an ancestor of this view.: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Monoceros_Sim/Monoceros-39.3/Core/EnvironmentObject.swift, line 55
Run Code Online (Sandbox Code Playgroud)
这是从 API 获取数据的 swift 文件,然后将数据保存到帖子
import Foundation
import Combine
final class NetworkManager: ObservableObject {
@Published var posts = [Post]()
func fetchData() …Run Code Online (Sandbox Code Playgroud) 去苹果开发者网站下载下面的教程项目:
https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation
在任何 iPad 模拟器上运行它,你只会得到一个空白页面,但代码在 Mac/iPhone 模拟器和我的真实 iPhone 设备上运行良好。
这绝对是一个错误,我已经向 Apple 报告了,我在这里发帖只是想要像我一样说这个问题的人,请不要在重置模拟器上浪费你的时间,检查你的代码,重启你的笔记本电脑,等到苹果来解决这个问题。
import SwiftUI
struct LandmarkList: View {
var body: some View {
NavigationView {
List(landmarkData) { landmark in
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
.navigationBarTitle(Text("Landmarks"))
}
}
}
struct LandmarkList_Previews: PreviewProvider {
static var previews: some View {
ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in
LandmarkList()
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
}
Run Code Online (Sandbox Code Playgroud) 当您为 Mac 应用程序或其他 iOS 编译 Xcode 时,您可能会看到以下错误
签署“gRPC-C++-gRPCCertificates-Cpp”需要一个开发团队。在 Signing & Capabilities 编辑器中选择一个开发团队。
我的 Xcode 版本:11.2.1 Mac OS:10.15.1