Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
771 views
in Technique[技术] by (71.8m points)

ios - Xcode Compiler Error: "Cannot find type 'Queue' in scope" while pare GPX file in swift

Xcode Compiler Erro

I'm follow this article but when I implement on my side it's occurred errors. Basically, I want to parse GPX File on my project. Please guide me solve this problem.

protocol GpxParsing: NSObjectProtocol {
    func parser(_ parser: GpxParser, didCompleteParsing locations: Queue<CLLocation>)
}
class GpxParser: NSObject, XMLParserDelegate {
    private var locations: Queue<CLLocation>
    weak var delegate: GpxParsing?
    private var parser: XMLParser?
    init(forResource file: String, ofType typeName: String) {
        self.locations = Queue<CLLocation>()
        super.init()
        if let content = try? String(contentsOfFile: Bundle.main.path(forResource: file, ofType: typeName)!) {
            let data = content.data(using: .utf8)
            parser = XMLParser.init(data: data!)
            parser?.delegate = self 
        }
    }
    func parse() {
        self.parser?.parse()
    }
    func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
        switch elementName {
        case "trkpt":
            if let latString =  attributeDict["lat"],
                let lat = Double.init(latString),
                let lonString = attributeDict["lon"],
                let lon = Double.init(lonString) {
                locations.enqueue(CLLocation(latitude: lat, longitude: lon))
            }
        default: break
        }
    }
    func parserDidEndDocument(_ parser: XMLParser) {
        delegate?.parser(self, didCompleteParsing: locations)
    }
}
question from:https://stackoverflow.com/questions/65907606/xcode-compiler-error-cannot-find-type-queue-in-scope-while-pare-gpx-file-in

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As the article quite clearly tells you:

Implementing a Queue should be trivial (or a good exercise to do).

In other words, the author has not included an implementation of Queue; instead, the author invites you to write it. As the author implies, this is an opportunity for you to learn what a Queue is and to write a generic Swift implementation of it. There is no Queue type because you didn't write one as the author of the article invites you to do. This was not a good article for you to copy if you are not willing to do some thinking and coding on your own.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...