From 45d5f29599c4f2f82f80efa84e16249fad5c1fbe Mon Sep 17 00:00:00 2001 From: thomas-em Date: Fri, 15 Jul 2016 16:08:17 +0200 Subject: [PATCH 1/3] Fix XMLParserDelegate method signatures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As NSXMLParser turned into XMLParser (without NS) there is a name clash now and SWXMLHash’s own XMLParser must be prefixed with Foundation for the delegate methods. Also, they must not be private. --- Source/SWXMLHash.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/SWXMLHash.swift b/Source/SWXMLHash.swift index f0a67f4e..3a4725a4 100644 --- a/Source/SWXMLHash.swift +++ b/Source/SWXMLHash.swift @@ -187,7 +187,7 @@ class LazyXMLParser: NSObject, SimpleXmlParser, XMLParserDelegate { parser.parse() } - private func parser(_ parser: XMLParser, + func parser(_ parser: Foundation.XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, @@ -202,7 +202,7 @@ class LazyXMLParser: NSObject, SimpleXmlParser, XMLParserDelegate { parentStack.push(currentNode) } - private func parser(_ parser: XMLParser, foundCharacters string: String) { + func parser(_ parser: Foundation.XMLParser, foundCharacters string: String) { if !onMatch() { return } @@ -212,7 +212,7 @@ class LazyXMLParser: NSObject, SimpleXmlParser, XMLParserDelegate { current.addText(string) } - private func parser(_ parser: XMLParser, + func parser(_ parser: Foundation.XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) { @@ -263,7 +263,7 @@ class XMLParser: NSObject, SimpleXmlParser, XMLParserDelegate { return XMLIndexer(root) } - private func parser(_ parser: XMLParser, + func parser(_ parser: Foundation.XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, @@ -273,13 +273,13 @@ class XMLParser: NSObject, SimpleXmlParser, XMLParserDelegate { parentStack.push(currentNode) } - private func parser(_ parser: XMLParser, foundCharacters string: String) { + func parser(_ parser: Foundation.XMLParser, foundCharacters string: String) { let current = parentStack.top() current.addText(string) } - private func parser(_ parser: XMLParser, + func parser(_ parser: Foundation.XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) { From 0ada1a9438b18eee2e2980b60f128bf92308f1b3 Mon Sep 17 00:00:00 2001 From: thomas-em Date: Fri, 15 Jul 2016 16:18:32 +0200 Subject: [PATCH 2/3] Fix deserialize() signature in XMLIndexerDeserializable adoptions --- SWXMLHashPlayground.playground/section-1.swift | 2 +- Tests/TypeConversionBasicTypesTests.swift | 2 +- Tests/TypeConversionComplexTypesTests.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SWXMLHashPlayground.playground/section-1.swift b/SWXMLHashPlayground.playground/section-1.swift index e1910993..e00ecdcd 100644 --- a/SWXMLHashPlayground.playground/section-1.swift +++ b/SWXMLHashPlayground.playground/section-1.swift @@ -78,7 +78,7 @@ struct Book: XMLIndexerDeserializable { let year: Int let amount: Int? - static func deserialize(node: XMLIndexer) throws -> Book { + static func deserialize(_ node: XMLIndexer) throws -> Book { return try Book( title: node["title"].value(), price: node["price"].value(), diff --git a/Tests/TypeConversionBasicTypesTests.swift b/Tests/TypeConversionBasicTypesTests.swift index c8bd6392..2cc1aa63 100644 --- a/Tests/TypeConversionBasicTypesTests.swift +++ b/Tests/TypeConversionBasicTypesTests.swift @@ -302,7 +302,7 @@ struct BasicItem: XMLIndexerDeserializable { let name: String let price: Double - static func deserialize(node: XMLIndexer) throws -> BasicItem { + static func deserialize(_ node: XMLIndexer) throws -> BasicItem { return try BasicItem( name: node["name"].value(), price: node["price"].value() diff --git a/Tests/TypeConversionComplexTypesTests.swift b/Tests/TypeConversionComplexTypesTests.swift index a4fea34f..baf296bb 100644 --- a/Tests/TypeConversionComplexTypesTests.swift +++ b/Tests/TypeConversionComplexTypesTests.swift @@ -113,7 +113,7 @@ struct ComplexItem: XMLIndexerDeserializable { let priceOptional: Double? let basics: [BasicItem] - static func deserialize(node: XMLIndexer) throws -> ComplexItem { + static func deserialize(_ node: XMLIndexer) throws -> ComplexItem { return try ComplexItem( name: node["name"].value(), priceOptional: node["price"].value(), From d1a6bcf968045221e712a71c299b1cb034a8cb79 Mon Sep 17 00:00:00 2001 From: thomas-em Date: Fri, 15 Jul 2016 16:20:35 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Shut=20up=20=C2=BBunused=20result=C2=AB=20w?= =?UTF-8?q?arnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SWXMLHash.swift | 6 +++--- Tests/XMLParsingTests.swift | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/SWXMLHash.swift b/Source/SWXMLHash.swift index 3a4725a4..58f3d2db 100644 --- a/Source/SWXMLHash.swift +++ b/Source/SWXMLHash.swift @@ -219,10 +219,10 @@ class LazyXMLParser: NSObject, SimpleXmlParser, XMLParserDelegate { let match = onMatch() - elementStack.pop() + let _ = elementStack.pop() if match { - parentStack.pop() + let _ = parentStack.pop() } } @@ -284,7 +284,7 @@ class XMLParser: NSObject, SimpleXmlParser, XMLParserDelegate { namespaceURI: String?, qualifiedName qName: String?) { - parentStack.pop() + let _ = parentStack.pop() } } diff --git a/Tests/XMLParsingTests.swift b/Tests/XMLParsingTests.swift index 7fc6734d..c7c94a28 100644 --- a/Tests/XMLParsingTests.swift +++ b/Tests/XMLParsingTests.swift @@ -132,7 +132,7 @@ class XMLParsingTests: XCTestCase { XCTAssertNotNil(err) } do { - try xml!.byKey("root").byKey("what").byKey("header").byKey("foo") + let _ = try xml!.byKey("root").byKey("what").byKey("header").byKey("foo") } catch let error as XMLIndexer.Error { err = error } catch { err = nil } @@ -144,7 +144,7 @@ class XMLParsingTests: XCTestCase { XCTAssertNotNil(err) } do { - try xml!.byKey("what").byKey("subelement").byIndex(5).byKey("nomatch") + let _ = try xml!.byKey("what").byKey("subelement").byIndex(5).byKey("nomatch") } catch let error as XMLIndexer.Error { err = error } catch { err = nil }