SwiftUI项目中的“使用未解析的标识符”

时间:2019-12-10 15:58:55

标签: swiftui swiftui-environment

我正在创建我的第一个SwiftUI项目。一切顺利,直到我向项目添加了新类(XML解析器)。现在,当我尝试调用新类时,出现错误“使用未解析的标识符”。似乎编译器不知道新类。

下面的代码已大大简化。希望我已经提供了足够的信息来传达这个想法:

import SwiftUI


struct SelectPumpView: View {

    @Environment(\.presentationMode) var presentation
    @State var sources:[FuelSource] = TestData.sources()

//    @State var fuelParser = PtXmlParser()


    var body: some View {
        NavigationView {

            GeometryReader { geometry in

                VStack {
                    VStack {
                        SelectPumpViewHeaderImage()
                        SelectPumpViewHeaderText()
                        TableColumnHeaderView()
                    } .frame(width: geometry.size.width, height: geometry.size.height/2, alignment: .top)

                    List (self.sources) { row in

                        // create a single row
                        HStack {
                            VStack (alignment: .leading ) {
                                Text("\(row.sourceID ?? "--")").font(.body)
                                    .frame(width: geometry.size.width/3 )
                            }
                            VStack {
                                Text("\(row.kFactor ?? "--")").font(.body)
                                    .frame(width: geometry.size.width/8 )
                            }
                            VStack {
                                Text("\(row.fuelType ?? "--")").font(.body)
                                    .frame(width: geometry.size.width/8 )
                            }
                            VStack (alignment: .trailing ) {
                                Text("\(row.units ?? "--")").font(.body)
                                    .frame(width: geometry.size.width/4 )
                            }
                        }
                    }
                    Button(action: {
                        // for debug only
                        for i in 0 ..< self.sources.count {
                            self.sources[i].debugPrint()
                        }
                    }) {
                        DisplayParseButton()
                    }
                } // end outer VStack
                .frame(width: geometry.size.width, height: geometry.size.height)

            }   // end GeometryView
        }   // end NavigationView
    }   // end View
}


还有解析器类...

import Foundation
import SwiftUI


class PtXmlParser: NSObject, XMLParserDelegate {

    override init() {
        super.init()
        if let path = Bundle.main.url(forResource: "FogTypes", withExtension: "xml") {
            if let parser = XMLParser(contentsOf: path) {
                parser.delegate = self
                parser.parse()
            }
        }
    }
    ...
    ...
}

0 个答案:

没有答案