Support Xcode8, Swift 3.0
This commit is contained in:
parent
5fd2e52ebe
commit
4a0b3a1de3
|
@ -187,7 +187,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = "Yahoo! Japan";
|
||||
TargetAttributes = {
|
||||
2B6D92321C7F0587000D2D06 = {
|
||||
|
@ -287,8 +287,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
@ -335,8 +337,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
@ -356,6 +360,7 @@
|
|||
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
|
@ -367,6 +372,7 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
|
@ -386,6 +392,7 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
|
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
@ -78,7 +78,7 @@ extension XML {
|
|||
```
|
||||
|
||||
*/
|
||||
private subscript(index index: Int) -> Accessor {
|
||||
fileprivate subscript(index index: Int) -> Accessor {
|
||||
let accessor: Accessor
|
||||
switch self {
|
||||
case .sequence(let elements) where index < elements.count:
|
||||
|
@ -118,7 +118,7 @@ extension XML {
|
|||
```
|
||||
|
||||
*/
|
||||
private subscript(key key: String) -> Accessor {
|
||||
fileprivate subscript(key key: String) -> Accessor {
|
||||
let accessor: Accessor
|
||||
switch self {
|
||||
case .singleElement(let element):
|
||||
|
@ -430,7 +430,7 @@ extension XML {
|
|||
}
|
||||
}
|
||||
|
||||
private func recursivePrintAncient(_ element: Element) -> String {
|
||||
fileprivate func recursivePrintAncient(_ element: Element) -> String {
|
||||
var description = element.name
|
||||
if let unwrappedParent = element.parentElement {
|
||||
description = recursivePrintAncient(unwrappedParent) + " > " + description
|
||||
|
@ -438,8 +438,8 @@ extension XML {
|
|||
return description
|
||||
}
|
||||
|
||||
private func accessError(_ description: String) -> Error {
|
||||
return Error.accessError(description: description)
|
||||
fileprivate func accessError(_ description: String) -> Error {
|
||||
return XMLError.accessError(description: description)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,17 +25,17 @@
|
|||
import Foundation
|
||||
|
||||
extension XML {
|
||||
public class Element {
|
||||
public var name: String
|
||||
public var text: String?
|
||||
public var attributes = [String: String]()
|
||||
public var childElements = [Element]()
|
||||
open class Element {
|
||||
open var name: String
|
||||
open var text: String?
|
||||
open var attributes = [String: String]()
|
||||
open var childElements = [Element]()
|
||||
|
||||
// for println
|
||||
public weak var parentElement: Element?
|
||||
open weak var parentElement: Element?
|
||||
|
||||
public init(name: String) {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
extension XML {
|
||||
public enum Error: ErrorProtocol {
|
||||
case parseError
|
||||
case accessError(description: String)
|
||||
}
|
||||
public enum XMLError: Error {
|
||||
case parseError
|
||||
case accessError(description: String)
|
||||
}
|
||||
|
|
|
@ -44,9 +44,9 @@ extension XML {
|
|||
}
|
||||
|
||||
// MARK:- private
|
||||
private var documentRoot = Element(name: "XML.Parser.AbstructedDocumentRoot")
|
||||
private var stack = [Element]()
|
||||
private let trimmingManner: CharacterSet?
|
||||
fileprivate var documentRoot = Element(name: "XML.Parser.AbstructedDocumentRoot")
|
||||
fileprivate var stack = [Element]()
|
||||
fileprivate let trimmingManner: CharacterSet?
|
||||
|
||||
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
|
||||
let node = Element(name: elementName)
|
||||
|
@ -63,9 +63,9 @@ extension XML {
|
|||
|
||||
func parser(_ parser: XMLParser, foundCharacters string: String) {
|
||||
if let text = stack.last?.text {
|
||||
stack.last?.text = text + (string ?? "")
|
||||
stack.last?.text = text + string
|
||||
} else {
|
||||
stack.last?.text = "" + (string ?? "")
|
||||
stack.last?.text = "" + string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public protocol XMLSubscriptType {}
|
|||
extension Int: XMLSubscriptType {}
|
||||
extension String: XMLSubscriptType {}
|
||||
|
||||
infix operator ?= {} // Failable Assignment
|
||||
infix operator ?= // Failable Assignment
|
||||
|
||||
/**
|
||||
assign value if rhs is not optonal. When rhs is optional, nothing to do.
|
||||
|
@ -40,7 +40,7 @@ public func ?=<T>(lhs: inout T, rhs: T?) {
|
|||
}
|
||||
}
|
||||
|
||||
infix operator ?<< {} // Failable Push
|
||||
infix operator ?<< // Failable Push
|
||||
|
||||
/**
|
||||
push value to array if rhs is not optonal. When rhs is optional, nothing to do.
|
||||
|
@ -85,14 +85,14 @@ public func ?<< <T>(lhs: inout [T], rhs: T?) {
|
|||
}
|
||||
```
|
||||
*/
|
||||
public class XML {
|
||||
open class XML {
|
||||
/**
|
||||
Interface to parse NSData
|
||||
|
||||
- parameter data:NSData XML document
|
||||
- returns:Accessor object to access XML document
|
||||
*/
|
||||
public class func parse(_ data: Data) -> Accessor {
|
||||
open class func parse(_ data: Data) -> Accessor {
|
||||
return Parser().parse(data)
|
||||
}
|
||||
|
||||
|
@ -102,9 +102,9 @@ public class XML {
|
|||
- Parameter str:String XML document
|
||||
- Returns:Accessor object to access XML document
|
||||
*/
|
||||
public class func parse(_ str: String) throws -> Accessor {
|
||||
open class func parse(_ str: String) throws -> Accessor {
|
||||
guard let data = str.data(using: String.Encoding.utf8) else {
|
||||
throw XML.Error.parseError
|
||||
throw XMLError.parseError
|
||||
}
|
||||
|
||||
return Parser().parse(data)
|
||||
|
@ -117,7 +117,7 @@ public class XML {
|
|||
- parameter manner:NSCharacterSet If you wannna trim Text, assign this arg
|
||||
- returns:Accessor object to access XML document
|
||||
*/
|
||||
public class func parse(_ data: Data, trimming manner: CharacterSet) -> Accessor {
|
||||
open class func parse(_ data: Data, trimming manner: CharacterSet) -> Accessor {
|
||||
return Parser(trimming: manner).parse(data)
|
||||
}
|
||||
|
||||
|
@ -128,9 +128,9 @@ public class XML {
|
|||
- parameter manner:NSCharacterSet If you wannna trim Text, assign this arg
|
||||
- Returns:Accessor object to access XML document
|
||||
*/
|
||||
public class func parse(_ str: String, trimming manner: CharacterSet) throws -> Accessor {
|
||||
open class func parse(_ str: String, trimming manner: CharacterSet) throws -> Accessor {
|
||||
guard let data = str.data(using: String.Encoding.utf8) else {
|
||||
throw XML.Error.parseError
|
||||
throw XMLError.parseError
|
||||
}
|
||||
|
||||
return Parser(trimming: manner).parse(data)
|
||||
|
|
|
@ -369,7 +369,7 @@ class AccessorTests: XCTestCase {
|
|||
XCTAssertEqual(failureResult.count, 0, "access failure element with for-in")
|
||||
}
|
||||
|
||||
private func singleElement() -> XML.Element {
|
||||
fileprivate func singleElement() -> XML.Element {
|
||||
let element = XML.Element(name: "RootElement")
|
||||
element.text = "text"
|
||||
element.attributes = ["key": "value"]
|
||||
|
@ -380,7 +380,7 @@ class AccessorTests: XCTestCase {
|
|||
return element
|
||||
}
|
||||
|
||||
private func sequence() -> [XML.Element] {
|
||||
fileprivate func sequence() -> [XML.Element] {
|
||||
let elem1 = XML.Element(name: "Element")
|
||||
elem1.text = "text"
|
||||
elem1.attributes = ["key": "value"]
|
||||
|
@ -398,7 +398,7 @@ class AccessorTests: XCTestCase {
|
|||
return elements
|
||||
}
|
||||
|
||||
private func failure() -> XML.Error {
|
||||
return XML.Error.accessError(description: "error")
|
||||
fileprivate func failure() -> XMLError {
|
||||
return XMLError.accessError(description: "error")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class ParserTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testSuccessParse() {
|
||||
guard let path = Bundle(for: self.dynamicType).pathForResource("XMLDocument", ofType: "xml"),
|
||||
guard let path = Bundle(for: type(of: self)).path(forResource: "XMLDocument", ofType: "xml"),
|
||||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
|
||||
XCTFail("fail to parse")
|
||||
return
|
||||
|
@ -55,7 +55,7 @@ class ParserTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testFailParse() {
|
||||
guard let path = Bundle(for: self.dynamicType).pathForResource("BrokenXMLDocument", ofType: "xml"),
|
||||
guard let path = Bundle(for: type(of: self)).path(forResource: "BrokenXMLDocument", ofType: "xml"),
|
||||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
|
||||
XCTFail("fail to parse")
|
||||
return
|
||||
|
@ -70,7 +70,7 @@ class ParserTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testTextParseWithMockData() {
|
||||
guard let path = Bundle(for: self.dynamicType).pathForResource("SimpleDocument", ofType: "xml"),
|
||||
guard let path = Bundle(for: type(of: self)).path(forResource: "SimpleDocument", ofType: "xml"),
|
||||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
|
||||
XCTFail("fail to parse")
|
||||
return
|
||||
|
@ -85,7 +85,7 @@ class ParserTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testWhitespaceParseWithMockData() {
|
||||
guard let path = Bundle(for: self.dynamicType).pathForResource("SimpleDocument", ofType: "xml"),
|
||||
guard let path = Bundle(for: type(of: self)).path(forResource: "SimpleDocument", ofType: "xml"),
|
||||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
|
||||
XCTFail("fail to parse")
|
||||
return
|
||||
|
@ -100,7 +100,7 @@ class ParserTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testReturnParseWithMockData() {
|
||||
guard let path = Bundle(for: self.dynamicType).pathForResource("SimpleDocument", ofType: "xml"),
|
||||
guard let path = Bundle(for: type(of: self)).path(forResource: "SimpleDocument", ofType: "xml"),
|
||||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
|
||||
XCTFail("fail to parse")
|
||||
return
|
||||
|
@ -115,7 +115,7 @@ class ParserTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testWhitespaceAndReturnParseWithMockData() {
|
||||
guard let path = Bundle(for: self.dynamicType).pathForResource("SimpleDocument", ofType: "xml"),
|
||||
guard let path = Bundle(for: type(of: self)).path(forResource: "SimpleDocument", ofType: "xml"),
|
||||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
|
||||
XCTFail("fail to parse")
|
||||
return
|
||||
|
@ -131,7 +131,7 @@ class ParserTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testWhitespaceAndReturnParseWithMockDataAndTrimmingWhitespaceAndLineBreak() {
|
||||
guard let path = Bundle(for: self.dynamicType).pathForResource("SimpleDocument", ofType: "xml"),
|
||||
guard let path = Bundle(for: type(of: self)).path(forResource: "SimpleDocument", ofType: "xml"),
|
||||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
|
||||
XCTFail("fail to parse")
|
||||
return
|
||||
|
|
|
@ -37,7 +37,7 @@ class XMLTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testParse() {
|
||||
if let path = Bundle(for: self.dynamicType).pathForResource("XMLDocument", ofType: "xml") {
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "XMLDocument", ofType: "xml") {
|
||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: path)) {
|
||||
let xml = XML.parse(data)
|
||||
if let _ = xml["ResultSet"].error {
|
||||
|
@ -56,7 +56,7 @@ class XMLTests: XCTestCase {
|
|||
|
||||
|
||||
func testSuccessParseFromString() {
|
||||
if let path = Bundle(for: self.dynamicType).pathForResource("XMLDocument", ofType: "xml"),
|
||||
if let path = Bundle(for: type(of: self)).path(forResource: "XMLDocument", ofType: "xml"),
|
||||
let string = try? String(contentsOfFile: path, encoding: String.Encoding.utf8),
|
||||
let xml = try? XML.parse(string) {
|
||||
if let _ = xml["ResultSet"].error {
|
||||
|
|
Loading…
Reference in New Issue