这是我的代码:
public class Payment: NSObject, NSXMLParserDelegate {
public var buchungsdatum:NSDate
public var valutadatum:NSDate
public var betrag:Double
public var verwendungszweck:String
public var creditorIban:String
public var creditorBic:String
public var creditorName:String
public var debitorIban:String
public var debitorBic:String
public var debitorName:String
override init() {
buchungsdatum = NSDate()
valutadatum = NSDate()
betrag = 0.0
verwendungszweck = ""
creditorIban = ""
creditorBic = ""
creditorName = ""
debitorBic = ""
debitorIban = ""
debitorName = ""
}
override public var description: String {
return "Payment-Information:"
}
func beginParse() {
let url = NSURL(fileURLWithPath: "/Users/Andi/Downloads/c53/CAMT/2015-10-06_C53_DE92300606010303502481_EUR_585142.xml")
let xml = NSXMLParser(contentsOfURL: url)!
xml.delegate = self
xml.parse()
}
@objc public func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
print("get an element")
}
@objc public func parserDidStartDocument(parser: NSXMLParser) {
print("started")
}
@objc public func parserDidEndDocument(parser: NSXMLParser) {
print("ended")
}
public func parser(parser: NSXMLParser, parseErrorOccurred parseError: NSError) {
print("Fehler")
}
}
var aPayment:Payment = Payment()
aPayment.beginParse()
任何人都可以告诉我为什么parse()返回false并且没有调用任何委托方法。即使是parseError也没有。我完全不明白为什么。
Xcode甚至表明XML-File有内容,而且url不是nil(见图) Xcode shows the XMLContent in the playground
答案 0 :(得分:-2)
这很可能是因为你的NSURL是零。