1

I am creating my 1st SwiftUI project. All was going well until I added a new class (an XML parser) to the project. Now I get the error "Use of unresolved identifier" when I try to invoke the new class. It seems like the compiler isn't aware of the new class.

The code below is greatly simplified. Hopefully I have provided enough to get the idea across:

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
}


And the parser class...

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()
            }
        }
    }
    ...
    ...
}
Bassman
  • 353
  • 5
  • 17

0 Answers0