Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SwiftUI Bug Fix";无法转换类型为';装订<;int>';到预期类型';装订<_>'&引用;_Ios_Swift_Xcode_Swiftui - Fatal编程技术网

Ios SwiftUI Bug Fix";无法转换类型为';装订<;int>';到预期类型';装订<_>'&引用;

Ios SwiftUI Bug Fix";无法转换类型为';装订<;int>';到预期类型';装订<_>'&引用;,ios,swift,xcode,swiftui,Ios,Swift,Xcode,Swiftui,我遇到此错误的问题: “无法将“Binding”类型的值转换为预期的“Binding”类型” 我想我用的是一个过时的SwiftUI版本,但我不是100%确定,所以我能得到的任何帮助都会很棒 我在下面显示了我的代码,以便您可以查看 我不确定底部是否重要,但我添加它只是为了安全 ContentView import SwiftUI struct ContentView: View { @State private var selection = 0 @State var netwo

我遇到此错误的问题:

“无法将“Binding”类型的值转换为预期的“Binding”类型”

我想我用的是一个过时的SwiftUI版本,但我不是100%确定,所以我能得到的任何帮助都会很棒

我在下面显示了我的代码,以便您可以查看

我不确定底部是否重要,但我添加它只是为了安全

ContentView

import SwiftUI

struct ContentView: View {
    @State private var selection = 0
    @State var networkManager = NetworkManager()
    var body: some View {
        TabView(selection: $selection){

            NavigationView{
            Text("First View")
                .font(.title)
                    .navigationBarTitle(Text("Welcome"))
                }
                .tabItem {
                    VStack {
                        Image(systemName: "star.fill")
                        Text("Welcome")
                    }
                }
                .tag(0)
            NavigationView{

                List(networkManager.featureList.results.identified(by: \.url)) { featured in
                Text(featured.name.capitalized)
                }
                    .navigationBarTitle(Text("Featured"))
                }
                .tabItem {
                    VStack {
                        Image(systemName: "app.badge.fill")
                        Text("Featured")
                    }
                }
                .tag(1)
            NavigationView{
            Text("First View")
                .font(.title)
                    .navigationBarTitle(Text("Repos"))
                }
            .tabItem {
                VStack {
                    Image(systemName: "rectangle.stack.fill")
                    Text("Repos")
                }
            }
            .tag(2)
            NavigationView{
            Text("First View")
                .font(.title)
                    .navigationBarTitle(Text("Request"))
                }
            .tabItem {
                VStack {
                    Image(systemName: "icloud.and.arrow.down.fill")
                    Text("Request")
                }
            }
            .tag(3)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
import Foundation
import SwiftUI
import Combine

class NetworkManager: ObservableObject {
    var didChange = PassthroughSubject<NetworkManager, Never>()
    var featureList = FeaturedApiList(results: []){
        didSet{
            didChange.send(self)
        }
    }

    init(){
        guard let url = URL(string: "https://myurl.com/repos.json") else { return }
        URLSession.shared.dataTask(with: url) { (data, _, _) in
            guard let data = data else { return }
            let featureList = try! JSONDecoder().decode(FeaturedApiList.self, from: data)
            DispatchQueue.main.async {
                self.featureList = featureList

            }
        }.resume()
    }
}
ApiView

import SwiftUI

struct ContentView: View {
    @State private var selection = 0
    @State var networkManager = NetworkManager()
    var body: some View {
        TabView(selection: $selection){

            NavigationView{
            Text("First View")
                .font(.title)
                    .navigationBarTitle(Text("Welcome"))
                }
                .tabItem {
                    VStack {
                        Image(systemName: "star.fill")
                        Text("Welcome")
                    }
                }
                .tag(0)
            NavigationView{

                List(networkManager.featureList.results.identified(by: \.url)) { featured in
                Text(featured.name.capitalized)
                }
                    .navigationBarTitle(Text("Featured"))
                }
                .tabItem {
                    VStack {
                        Image(systemName: "app.badge.fill")
                        Text("Featured")
                    }
                }
                .tag(1)
            NavigationView{
            Text("First View")
                .font(.title)
                    .navigationBarTitle(Text("Repos"))
                }
            .tabItem {
                VStack {
                    Image(systemName: "rectangle.stack.fill")
                    Text("Repos")
                }
            }
            .tag(2)
            NavigationView{
            Text("First View")
                .font(.title)
                    .navigationBarTitle(Text("Request"))
                }
            .tabItem {
                VStack {
                    Image(systemName: "icloud.and.arrow.down.fill")
                    Text("Request")
                }
            }
            .tag(3)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
import Foundation
import SwiftUI
import Combine

class NetworkManager: ObservableObject {
    var didChange = PassthroughSubject<NetworkManager, Never>()
    var featureList = FeaturedApiList(results: []){
        didSet{
            didChange.send(self)
        }
    }

    init(){
        guard let url = URL(string: "https://myurl.com/repos.json") else { return }
        URLSession.shared.dataTask(with: url) { (data, _, _) in
            guard let data = data else { return }
            let featureList = try! JSONDecoder().decode(FeaturedApiList.self, from: data)
            DispatchQueue.main.async {
                self.featureList = featureList

            }
        }.resume()
    }
}
<代码>导入基础 导入快捷键 进口联合收割机 类网络管理器:ObserveObject{ var didChange=PassthroughSubject() var featureList=FeaturedApiList(结果:[]){ 迪塞特{ 发送(自我) } } init(){ guard let url=url(字符串:https://myurl.com/repos.json)否则{return} URLSession.shared.dataTask(带:url){(数据,,)在 guard let data=data else{return} 让featureList=try!JSONDecoder().decode(FeaturedApiList.self,from:data) DispatchQueue.main.async{ self.featureList=功能列表 } }1.简历() } }
谢谢

显示的错误非常混乱,但其他一些错误会导致此类错误

在您的情况下,可能需要修复
选项卡视图
中的第二个
导航视图

            NavigationView{
                //↓Fix this line.
                List(networkManager.featureList.results, id: \.url) { featured in
                    Text(featured.name.capitalized)
                }
                .navigationBarTitle(Text("Featured"))
            }
            .tabItem {
                VStack {
                    Image(systemName: "app.badge.fill")
                    Text("Featured")
                }
            }
            .tag(1)

最好检查并始终尝试查找最新的示例或教程。

欢迎使用Stackoverflow

OOPer实际上是正确的。您需要修复
列表
。 让我们尝试替换
列表中的数据
,以查看项目将编译:

假设我们有一个符合
可识别的
协议的模型,如下所示:

struct Person: Identifiable {
    var id = UUID()
    var name: String
}
然后将您的
列表
行替换为以下内容:

List([Person(name: "fafa")]) { featured in
    Text(featured.name)
}
这次它应该运行。由于SwiftUI是新的,这一定是导致错误相当混乱的原因