- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
自从今天早些时候更新到 Xcode Beta 6 后,我的应用程序将不再构建,它在 Beta 5 和更早版本中运行良好。
这是带有错误消息的文件中的代码,尽管我目前知道这并不一定意味着错误实际出处。
import SwiftUI
struct JobView_Table : View {
@ObservedObject var jobList: JobDetailViewModel = JobDetailViewModel()
var body: some View {
NavigationView {
List {
ForEach($jobList.jobDetails) { job in
NavigationLink(destination: JobDetailHost(jobDetails: job)) { // ERROR: "Type of expression is ambiguous without more context"
JobView_List(jobDetails: job)
}
}
}
.navigationBarTitle(Text("My Jobs"))
.onAppear(perform: fetchData)
.onAppear(perform: {
print("Hello!")
})
}
}
private func fetchData() {
return(jobList.updateDetails())
}
}
包含数据的结构正确地符合以下协议(protocol)。
struct JobDetails: Codable, Identifiable, Equatable, Hashable {
...
...
}
这是向 JobView_Table
提供数据的类。
import Foundation
import UIKit
import Combine
class JobDetailViewModel: ObservableObject, Identifiable {
@Published var jobDetails: [JobDetails] = []
func updateDetails() {
self.jobDetails = DataManager().fetchJobList()
}
}
最后是通过 NavigationLink
链接到的目标 View 。
struct JobDetailHost: View {
@Environment(\.editMode) var mode
@Binding var jobDetails: JobDetails
var body: some View {
VStack {
JobDetailView(jobDetails: jobDetails)
}
.navigationBarItems(trailing: EditButton())
}
}
我注意到其他一些人似乎也有类似的问题,即在下面列出的两个问题中,但目前探索这些问题的答案对我没有帮助。 SwiftUI Xcode 11 beta 5 / 6: Type of expression is ambiguous without more context
SwiftUI: Why does ForEach($strings) (text: Binding) not build?
编辑:
我已经尝试实现 Fabian 的建议,这已经消除了错误,但是列表中没有填充任何内容。
这是调整后的 List
代码,它编译成功,但在运行应用程序时列表未填充。
List {
ForEach(jobList.jobDetails.indexed(), id: \.1.id) { (index, job) in
NavigationLink(destination: JobDetailHost(jobDetails: self.$jobList.jobDetails[index])) {
Text(job.jobName)
}
}
}
下面没有使用ForEach
,丢弃了NavigationLink
,还是不行。
List(jobList.jobDetails.indexed(), id: \.1.id) { (index, job) in
Text(job.jobName)
}
最佳答案
我会引用 macOS Catalina 10.15 Beta 6 Release Notes :
The Binding structure’s conditional conformance to the Collection protocol is removed. (51624798)
If you have code such as the following:
struct LandmarkList: View {
@Binding var landmark: [Landmark]
var body: some View {
List(landmarks) { landmark in
Toggle(landmark.value.name, isOn: landmark[\.isFavorite])
}
}
}Define the following collection type:
struct IndexedCollection<Base: RandomAccessCollection>: RandomAccessCollection {
typealias Index = Base.Index
typealias Element = (index: Index, element: Base.Element)
let base: Base
var startIndex: Index { base.startIndex }
var endIndex: Index { base.endIndex }
func index(after i: Index) -> Index {
base.index(after: i)
}
func index(before i: Index) -> Index {
base.index(before: i)
}
func index(_ i: Index, offsetBy distance: Int) -> Index {
base.index(i, offsetBy: distance)
}
subscript(position: Index) -> Element {
(index: position, element: base[position])
}
}
extension RandomAccessCollection {
func indexed() -> IndexedCollection<Self> {
IndexedCollection(base: self)
}
}Then, update your code to:
struct LandmarkList: View {
@Binding var landmarks: [Landmark]
var body: some View { // Does often give error on id: \.1.id
List(landmarks.indexed(), id: \.1.id) { (index, landmark) in
Toggle(landmark.name, isOn: self.$landmarks[index].isFavorite)
}
}
}
您的代码还需要一个 Binding<[JobDetails]>
与 $jobList.jobDetails
,但是Binding<[JobDetails]>
不再符合 Collection 协议(protocol)。
但是请注意上面的解决方案,我遇到了 \.1.id
的情况未被识别,因为编译器不理解 \.1
指的是元组中的第二个元素 IndexedCollection
定义,但有可能我用错了。可以重写它,但它可以正常工作。
struct AnotherIndexedView_NeedsEnv: View {
@EnvironmentObject var modalManager: ModalManager
var body: some View {
ZStack {
SwiftUI.ForEach(modalManager.modals.indexed()) { m in
ModalView(currentModal: self.$modalManager.modals[m.index]).environmentObject(self.modalManager)
}
}.onAppear(perform: {self.modalManager.fetchContent()})
}
}
关于swift - Xcode Beta 6 "Type of expression is ambiguous without more context"导航链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57580748/
我正在尝试加载外部 SVG 并将其附加到 Electron 项目中的现有 SVG。 d3.xml 方法对我不起作用,所以我正在查看 d3.symbols ,希望如果我提供路径数据(来自 fs.read
我正在编写一个 Web 应用程序,使用 Go 作为后端。我正在使用这个 GraphQL 库 (link)和 Echo Web 框架 (link) .问题在于 graphql-go 库在 Go 中使用了
有没有办法改造 gin.Context至 context.Context在围棋?构建 Go 微服务应该使用什么? 最佳答案 标准库的 context.Context type 是一个接口(interf
如果我能够像这样注册一个接收器: LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new Inte
如果我有 appengine.Context 而不是 ,我不知道如何调用 cloud.WithContext 和 google.DefaultClient >上下文。上下文。 有(旧的)“appeng
有什么区别- AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SER
我刚读了这篇文章:Build You Own Web Framework In Go为了在处理程序之间共享值,我选择了 context.Context我通过以下方式使用它在处理程序和中间件之间共享值:
在 Visual Studio Code 中,我对 3 个“上下文”菜单项感到非常困惑:Run Tests in Context和 Debug Tests in Context和 Run .NET C
我正在使用带有 和 @Autowired 的 Spring 2.5.6 版本。 虽然我在调度程序上下文中使用 SimpleUrlHandlerMapping ,但一切正常 - Autowiring 工
我使用的是 Context.registerReceiver()、Context.sendBroadcast(Intent) 和 Context.unregisterReceiver() 但是当我看到
问题在于以下错误, [错误] 在 scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4580)[错误] 在 scal
最近我正在尝试使用 SoundPool 在我的应用程序中播放一些简单的音效 但不幸的是它在 AVD 中不起作用并且应用程序崩溃 “上下文”到底是什么意思? 完全不懂 提前致谢 最佳答案 任何上下文都允
我正在使用上下文建议器,我想知道我们是否可以设置用于建议的上下文范围,而不是使用所有上下文。 目前查询需要匹配所有上下文。我们能否在上下文中添加“或”运算和/或指定用于特定查询的上下文? 以here为
我被一个使用这种方法的函数卡住了。所以我知道如何使用 expressionValue(with:context:) 函数,但上下文如何参与对我来说仍然是不透明的。也许有人有简单的例子? try tra
我正在尝试在上下文管理器中更改我的 python 程序中的目录。使用 invoke.context.Context 似乎是正确的方法,从 Fabric 文档中获取并且使用常规 with os.chdi
我最近开始使用 Android Studio 处理我的 Android 项目。我注意到在 IDE 的右下角,有文本 Context: .好奇心打败了我,所以现在我正在网上搜索更多信息。我还没有找到任
假设我有这些功能: func A(ctx context.Context) { // A takes some time to process } func B(ctx context.Con
所以,我有一个 context.Context( https://golang.org/pkg/context/ ) 变量,有没有办法列出这个变量包含的所有键? 最佳答案 可以使用不安全反射列出 co
我正在尝试找出传播 context.Context 的正确方法用于在使用 Gin 时使用 OpenTelemetry 进行跟踪。 我目前有一个 gin调用函数并传递 *gin.Context 的处理程
我们可以使用 Remove["context`*"] 删除特定上下文中的所有符号。 .但是是否可以删除 "context`"自己从系统中删除,以便它不再在 Contexts[] 中列出? 最佳答案 据
我是一名优秀的程序员,十分优秀!