Use modern Swift 2.0

This commit is contained in:
Kyle Fuller
2015-09-25 10:40:58 -07:00
parent a0bde992c2
commit 878c5cfde8
3 changed files with 14 additions and 17 deletions

View File

@@ -1,13 +1,13 @@
import Foundation
/// A container for template variables.
public class Context : Equatable {
var dictionaries:[Dictionary<String, AnyObject>]
var dictionaries:[[String:AnyObject]]
public init(dictionary:Dictionary<String, AnyObject>) {
/// Initialise a Context with a dictionary
public init(dictionary:[String:AnyObject]) {
dictionaries = [dictionary]
}
/// Initialise an empty Context
public init() {
dictionaries = []
}
@@ -16,7 +16,7 @@ public class Context : Equatable {
/// Retrieves a variable's value, starting at the current context and going upwards
get {
for dictionary in Array(dictionaries.reverse()) {
if let value:AnyObject = dictionary[key] {
if let value = dictionary[key] {
return value
}
}
@@ -26,24 +26,21 @@ public class Context : Equatable {
/// Set a variable in the current context, deleting the variable if it's nil
set(value) {
if dictionaries.count > 0 {
var dictionary = dictionaries.removeLast()
if var dictionary = dictionaries.popLast() {
dictionary[key] = value
dictionaries.append(dictionary)
}
}
}
public func push() {
push(Dictionary<String, AnyObject>())
/// Push a new level into the Context
public func push(dictionary:[String:AnyObject]? = nil) {
dictionaries.append(dictionary ?? [:])
}
public func push(dictionary:Dictionary<String, AnyObject>) {
dictionaries.append(dictionary)
}
public func pop() {
dictionaries.removeLast()
/// Pop the last level off of the Context
public func pop() -> [String:AnyObject]? {
return dictionaries.popLast()
}
}

View File

@@ -28,7 +28,7 @@ public class TokenParser {
}
private var tokens:[Token]
private var tags = Dictionary<String, TagParser>()
private var tags = [String:TagParser]()
public init(tokens:[Token]) {
self.tokens = tokens

View File

@@ -25,7 +25,7 @@ public struct Variable : Equatable {
for bit in lookup() {
if let context = current as? Context {
current = context[bit]
} else if let dictionary = current as? Dictionary<String, AnyObject> {
} else if let dictionary = current as? [String:AnyObject] {
current = dictionary[bit]
} else if let array = current as? [AnyObject] {
if let index = Int(bit) {