Skip to content

Commit

Permalink
Fixed build warnings and errors in Xcode 8 GM (8A218a)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadija committed Sep 10, 2016
1 parent cd0b563 commit 1525ea9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 39 deletions.
15 changes: 15 additions & 0 deletions AEXML.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,27 @@
};
8B4A92891BDD49390011F36F = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
8B4A92981BDD4CEF0011F36F = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
8B4A92AA1BDD54F50011F36F = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
8B4A92BD1BDD5B300011F36F = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
8B4A92CB1BDD5BB20011F36F = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
8B4A92DE1BDD5D330011F36F = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -640,6 +645,7 @@
PRODUCT_NAME = AEXML;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -666,6 +672,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -712,6 +719,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "net.tadija.AEXML-OSX-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -730,6 +738,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -750,6 +759,7 @@
PRODUCT_NAME = AEXML;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -774,6 +784,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -789,6 +800,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "net.tadija.AEXML-tvOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
Expand All @@ -805,6 +817,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
Expand All @@ -827,6 +840,7 @@
PRODUCT_NAME = AEXML;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -854,6 +868,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down
78 changes: 39 additions & 39 deletions Sources/AEXML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,50 @@ import Foundation
You can access its structure by using subscript like this: `element["foo"]["bar"]` which would
return `<bar></bar>` element from `<element><foo><bar></bar></foo></element>` XML as an `AEXMLElement` object.
*/
public class AEXMLElement {
open class AEXMLElement {

/// A type representing an error value that can be inside `error` property.
public enum AEXMLError: Error {
case elementNotFound
case rootElementMissing
}

private struct Defaults {
fileprivate struct Defaults {
static let name = String()
static let attributes = [String : String]()
}

// MARK: Properties

/// Every `AEXMLElement` should have its parent element instead of `AEXMLDocument` which parent is `nil`.
public internal(set) weak var parent: AEXMLElement?
open internal(set) weak var parent: AEXMLElement?

/// Child XML elements.
public internal(set) var children: [AEXMLElement] = [AEXMLElement]()
open internal(set) var children: [AEXMLElement] = [AEXMLElement]()

/// XML Element name (defaults to empty string).
public var name: String
open var name: String

/// XML Element value.
public var value: String?
open var value: String?

/// XML Element attributes (defaults to empty dictionary).
public var attributes: [String : String]
open var attributes: [String : String]

/// Error value (`nil` if there is no error).
public var error: AEXMLError?
open var error: AEXMLError?

/// String representation of `value` property (if `value` is `nil` this is empty String).
public var stringValue: String { return value ?? String() }
open var stringValue: String { return value ?? String() }

/// Boolean representation of `value` property (if `value` is "true" or 1 this is `True`, otherwise `False`).
public var boolValue: Bool { return stringValue.lowercased() == "true" || Int(stringValue) == 1 ? true : false }
open var boolValue: Bool { return stringValue.lowercased() == "true" || Int(stringValue) == 1 ? true : false }

/// Integer representation of `value` property (this is **0** if `value` can't be represented as Integer).
public var intValue: Int { return Int(stringValue) ?? 0 }
open var intValue: Int { return Int(stringValue) ?? 0 }

/// Double representation of `value` property (this is **0.00** if `value` can't be represented as Double).
public var doubleValue: Double { return (stringValue as NSString).doubleValue }
open var doubleValue: Double { return (stringValue as NSString).doubleValue }

// MARK: Lifecycle

Expand All @@ -97,7 +97,7 @@ public class AEXMLElement {
// MARK: XML Read

/// The first element with given name **(Empty element with error if not exists)**.
public subscript(key: String) -> AEXMLElement {
open subscript(key: String) -> AEXMLElement {
guard let
first = children.filter({ $0.name == key }).first
else {
Expand All @@ -109,18 +109,18 @@ public class AEXMLElement {
}

/// Returns all of the elements with equal name as `self` **(nil if not exists)**.
public var all: [AEXMLElement]? { return parent?.children.filter { $0.name == self.name } }
open var all: [AEXMLElement]? { return parent?.children.filter { $0.name == self.name } }

/// Returns the first element with equal name as `self` **(nil if not exists)**.
public var first: AEXMLElement? { return all?.first }
open var first: AEXMLElement? { return all?.first }

/// Returns the last element with equal name as `self` **(nil if not exists)**.
public var last: AEXMLElement? { return all?.last }
open var last: AEXMLElement? { return all?.last }

/// Returns number of all elements with equal name as `self`.
public var count: Int { return all?.count ?? 0 }
open var count: Int { return all?.count ?? 0 }

private func allWith(condition: (_ element: AEXMLElement) -> Bool) -> [AEXMLElement]? {
fileprivate func allWith(_ condition: (_ element: AEXMLElement) -> Bool) -> [AEXMLElement]? {
var found = [AEXMLElement]()
if let elements = all {
for element in elements {
Expand All @@ -141,7 +141,7 @@ public class AEXMLElement {
- returns: Optional Array of found XML elements.
*/
public func allWith(value: String) -> [AEXMLElement]? {
open func allWith(value: String) -> [AEXMLElement]? {
let found = allWith { (element) -> Bool in
return element.value == value
}
Expand All @@ -155,7 +155,7 @@ public class AEXMLElement {
- returns: Optional Array of found XML elements.
*/
public func allWith(attributes: [String : String]) -> [AEXMLElement]? {
open func allWith(attributes: [String : String]) -> [AEXMLElement]? {
let found = allWith { (element) -> Bool in
var countAttributes = 0
for (key, value) in attributes {
Expand All @@ -177,7 +177,7 @@ public class AEXMLElement {
- returns: Child XML element with `self` as `parent`.
*/
public func addChild(_ child: AEXMLElement) -> AEXMLElement {
open func addChild(_ child: AEXMLElement) -> AEXMLElement {
child.parent = self
children.append(child)
return child
Expand All @@ -192,23 +192,23 @@ public class AEXMLElement {
- returns: Child XML element with `self` as `parent`.
*/
public func addChild(name: String, value: String? = nil, attributes: [String : String]? = nil) -> AEXMLElement {
open func addChild(name: String, value: String? = nil, attributes: [String : String]? = nil) -> AEXMLElement {
let child = AEXMLElement(name, value: value, attributes: attributes)
return addChild(child)
}

/// Removes `self` from `parent` XML element.
public func removeFromParent() {
open func removeFromParent() {
parent?.removeChild(self)
}

private func removeChild(_ child: AEXMLElement) {
fileprivate func removeChild(_ child: AEXMLElement) {
if let childIndex = children.index(where: { $0 === child }) {
children.remove(at: childIndex)
}
}

private var parentsCount: Int {
fileprivate var parentsCount: Int {
var count = 0
var element = self
while let parent = element.parent {
Expand All @@ -218,7 +218,7 @@ public class AEXMLElement {
return count
}

private func indentation(_ depth: Int) -> String {
fileprivate func indentation(_ depth: Int) -> String {
var count = depth
var indent = String()

Expand All @@ -231,7 +231,7 @@ public class AEXMLElement {
}

/// Complete hierarchy of `self` and `children` in **XML** escaped and formatted String
public var xmlString: String {
open var xmlString: String {
var xml = String()

// open element
Expand Down Expand Up @@ -268,7 +268,7 @@ public class AEXMLElement {
}

/// Same as `xmlString` but without `\n` and `\t` characters
public var xmlStringCompact: String {
open var xmlStringCompact: String {
let chars = CharacterSet(charactersIn: "\n\t")
return xmlString.components(separatedBy: chars).joined(separator: "")
}
Expand Down Expand Up @@ -300,9 +300,9 @@ public extension String {
XML Parsing is also done with this object.
*/
public class AEXMLDocument: AEXMLElement {
open class AEXMLDocument: AEXMLElement {

private struct Defaults {
fileprivate struct Defaults {
static let version = 1.0
static let encoding = "utf-8"
static let standalone = "no"
Expand All @@ -321,19 +321,19 @@ public class AEXMLDocument: AEXMLElement {
// MARK: Properties

/// This is only used for XML Document header (default value is 1.0).
public let version: Double
open let version: Double

/// This is only used for XML Document header (default value is "utf-8").
public let encoding: String
open let encoding: String

/// This is only used for XML Document header (default value is "no").
public let standalone: String
open let standalone: String

/// Options for NSXMLParser (default values are `false`)
public let xmlParserOptions: NSXMLParserOptions
open let xmlParserOptions: NSXMLParserOptions

/// Root (the first child element) element of XML Document **(Empty element with error if not exists)**.
public var root: AEXMLElement {
open var root: AEXMLElement {
guard let rootElement = children.first else {
let errorElement = AEXMLElement()
errorElement.error = AEXMLError.rootElementMissing
Expand Down Expand Up @@ -408,7 +408,7 @@ public class AEXMLDocument: AEXMLElement {
- parameter data: XML which should be parsed.
*/
public func loadXMLData(_ data: Data) throws {
open func loadXMLData(_ data: Data) throws {
children.removeAll(keepingCapacity: false)
let xmlParser = AEXMLParser(xmlDocument: self, xmlData: data)
try xmlParser.parse()
Expand All @@ -417,7 +417,7 @@ public class AEXMLDocument: AEXMLElement {
// MARK: Override

/// Override of `xmlString` property of `AEXMLElement` - it just inserts XML Document header at the beginning.
public override var xmlString: String {
open override var xmlString: String {
var xml = "<?xml version=\"\(version)\" encoding=\"\(encoding)\" standalone=\"\(standalone)\"?>\n"
for child in children {
xml += child.xmlString
Expand Down Expand Up @@ -485,8 +485,8 @@ private class AEXMLParser: NSObject, XMLParserDelegate {
currentElement = nil
}

@objc func parser(_ parser: XMLParser, parseErrorOccurred parseError: NSError) {
self.parseError = parseError
@objc func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error) {
self.parseError = parseError as NSError?
}

}

0 comments on commit 1525ea9

Please sign in to comment.