Skip to content

Commit 327bb9c

Browse files
committed
Updated to the new Swift 2.0 syntax.
1 parent 8b55c65 commit 327bb9c

10 files changed

+78
-57
lines changed

JSON.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@
355355
7D7BD7B9195418CB00AC2E4E /* Project object */ = {
356356
isa = PBXProject;
357357
attributes = {
358+
LastSwiftUpdateCheck = 0700;
358359
LastUpgradeCheck = 0600;
359360
ORGANIZATIONNAME = owensd.io;
360361
TargetAttributes = {

src/Error.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct ErrorKeys {
4343
public static let FilePath = "NSFilePath"
4444
}
4545

46-
extension Error: Printable {
46+
extension Error: CustomStringConvertible {
4747
public var description: String {
4848
return "an error..."
4949
}

src/Functional.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ infix operator ⇒ { associativity left precedence 150 }
1010

1111
/// Allows for a transformative function to be applied to a value, allowing for optionals.
1212
///
13-
/// :param: lhs The transformative function
14-
/// :param: rhs The value to apply to the function
15-
/// :returns: The transformation of `rhs` using `lhs`.
13+
/// - parameter lhs: The transformative function
14+
/// - parameter rhs: The value to apply to the function
15+
/// - returns: The transformation of `rhs` using `lhs`.
1616
public func <A, B>(lhs: (A -> B)?, rhs: A?) -> B? {
1717
if let lhs = lhs {
1818
if let rhs = rhs {
@@ -25,9 +25,9 @@ public func ⇒ <A, B>(lhs: (A -> B)?, rhs: A?) -> B? {
2525

2626
/// Allows for a value to be transformed by a function, allowing for optionals.
2727
///
28-
/// :param: lhs The value to apply to the function
29-
/// :param: rhs The transformative function
30-
/// :returns: The transformation of `lhs` using `rhs`.
28+
/// - parameter lhs: The value to apply to the function
29+
/// - parameter rhs: The transformative function
30+
/// - returns: The transformation of `lhs` using `rhs`.
3131
public func <A, B>(lhs: A?, rhs: (A -> B)?) -> B? {
3232
if let lhs = lhs {
3333
if let rhs = rhs {
@@ -40,15 +40,15 @@ public func ⇒ <A, B>(lhs: A?, rhs: (A -> B)?) -> B? {
4040

4141
/// Allows for a transformative function to be applied to a value.
4242
///
43-
/// :param: lhs The transformative function
44-
/// :param: rhs The value to apply to the function
45-
/// :returns: The transformation of `rhs` using `lhs`.
43+
/// - parameter lhs: The transformative function
44+
/// - parameter rhs: The value to apply to the function
45+
/// - returns: The transformation of `rhs` using `lhs`.
4646
public func <A, B>(lhs: A -> B, rhs: A) -> B { return lhs(rhs) }
4747

4848

4949
/// Allows for a value to be transformed by a function.
5050
///
51-
/// :param: lhs The value to apply to the function
52-
/// :param: rhs The transformative function
53-
/// :returns: The transformation of `lhs` using `rhs`.
51+
/// - parameter lhs: The value to apply to the function
52+
/// - parameter rhs: The transformative function
53+
/// - returns: The transformation of `lhs` using `rhs`.
5454
public func <A, B>(lhs: A, rhs: A -> B) -> B { return rhs(lhs) }

src/JSValue.Accessors.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension JSValue {
1414

1515
/// Attempts to retrieve a `String` out of the `JSValue`.
1616
///
17-
/// :returns: If the `JSValue` is a `JSString`, then the stored `String` value is returned, otherwise `nil`.
17+
/// - returns: If the `JSValue` is a `JSString`, then the stored `String` value is returned, otherwise `nil`.
1818
public var string: String? {
1919
switch self.value {
2020
case .JSString(let value): return value
@@ -24,7 +24,7 @@ extension JSValue {
2424

2525
/// Attempts to retrieve a `Double` out of the `JSValue`.
2626
///
27-
/// :returns: If the `JSValue` is a `JSNumber`, then the stored `Double` value is returned, otherwise `nil`.
27+
/// - returns: If the `JSValue` is a `JSNumber`, then the stored `Double` value is returned, otherwise `nil`.
2828
public var number: Double? {
2929
switch self.value {
3030
case .JSNumber(let value): return value
@@ -34,7 +34,7 @@ extension JSValue {
3434

3535
/// Attempts to retrieve a `Bool` out of the `JSValue`.
3636
///
37-
/// :returns: If the `JSValue` is a `JSBool`, then the stored `Double` value is returned, otherwise `nil`.
37+
/// - returns: If the `JSValue` is a `JSBool`, then the stored `Double` value is returned, otherwise `nil`.
3838
public var bool: Bool? {
3939
switch self.value {
4040
case .JSBool(let value): return value
@@ -44,7 +44,7 @@ extension JSValue {
4444

4545
/// Attempts to retrieve a `[String:JSValue]` out of the `JSValue`.
4646
///
47-
/// :returns: If the `JSValue` is a `JSObject`, then the stored `[String:JSValue]` value is returned, otherwise `nil`.
47+
/// - returns: If the `JSValue` is a `JSObject`, then the stored `[String:JSValue]` value is returned, otherwise `nil`.
4848
public var object: [String:JSValue]? {
4949
switch self.value {
5050
case .JSObject(let value): return value
@@ -54,7 +54,7 @@ extension JSValue {
5454

5555
/// Attempts to retrieve a `[JSValue]` out of the `JSValue`.
5656
///
57-
/// :returns: If the `JSValue` is a `JSArray`, then the stored `[JSValue]` value is returned, otherwise `nil`.
57+
/// - returns: If the `JSValue` is a `JSArray`, then the stored `[JSValue]` value is returned, otherwise `nil`.
5858
public var array: [JSValue]? {
5959
switch self.value {
6060
case .JSArray(let value): return value
@@ -64,7 +64,7 @@ extension JSValue {
6464

6565
/// Used to determine if a `nil` value is stored within `JSValue`. There is no intrinsic type for this value.
6666
///
67-
/// :returns: If the `JSValue` is a `JSNull`, then the `true` is returned, otherwise `false`.
67+
/// - returns: If the `JSValue` is a `JSNull`, then the `true` is returned, otherwise `false`.
6868
public var null: Bool {
6969
switch self.value {
7070
case .JSNull: return true
@@ -74,7 +74,7 @@ extension JSValue {
7474

7575
/// Determines if the `JSValue` has a value stored within it.
7676
///
77-
/// :returns: `true` if the `JSValue` has a valid value stored, `false` if the `JSValue` is `Invalid`.
77+
/// - returns: `true` if the `JSValue` has a valid value stored, `false` if the `JSValue` is `Invalid`.
7878
public var hasValue: Bool {
7979
switch self.value {
8080
case .Invalid(_): return false

src/JSValue.Indexers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extension JSValue {
1010

1111
/// Attempts to treat the `JSValue` as a `JSObject` and perform the lookup.
1212
///
13-
/// :returns: A `JSValue` that represents the value found at `key`
13+
/// - returns: A `JSValue` that represents the value found at `key`
1414
public subscript(key: String) -> JSValue {
1515
get {
1616
if let dict = self.object {

src/JSValue.Parsing.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ extension JSValue {
2929

3030
/// Parses the given sequence of UTF8 code points and attempts to return a `JSValue` from it.
3131
///
32-
/// :param: seq The sequence of UTF8 code points.
32+
/// - parameter seq: The sequence of UTF8 code points.
3333
///
34-
/// :returns: A `JSParsingResult` containing the parsed `JSValue` or error information.
34+
/// - returns: A `JSParsingResult` containing the parsed `JSValue` or error information.
3535
public static func parse(seq: JSParsingSequence) -> JSParsingResult {
36-
var generator = ReplayableGenerator(seq)
36+
let generator = ReplayableGenerator(seq)
3737

3838
let result = parse(generator)
3939
if let value = result.value {
4040
for codeunit in generator {
4141
if codeunit.isWhitespace() { continue }
4242
else {
43-
var remainingText = substring(generator)
43+
let remainingText = substring(generator)
4444

4545
let info = [
4646
ErrorKeys.LocalizedDescription: ErrorCode.ParsingError.message,
@@ -99,7 +99,7 @@ extension JSValue {
9999
var key = ""
100100
var object = JSObjectType()
101101

102-
for (idx, codeunit) in enumerate(generator) {
102+
for (idx, codeunit) in generator.enumerate() {
103103
switch (idx, codeunit) {
104104
case (0, Token.LeftCurly): continue
105105
case (_, Token.RightCurly):
@@ -192,7 +192,7 @@ extension JSValue {
192192
static func parseArray<S: SequenceType where S.Generator.Element == UInt8>(generator: ReplayableGenerator<S>) -> JSParsingResult {
193193
var values = [JSValue]()
194194

195-
for (idx, codeunit) in enumerate(generator) {
195+
for (idx, codeunit) in generator.enumerate() {
196196
switch (idx, codeunit) {
197197
case (0, Token.LeftBracket): continue
198198
case (_, Token.RightBracket):
@@ -236,7 +236,7 @@ extension JSValue {
236236
var exponent = 0
237237
var exponentSign = 1
238238

239-
for (idx, codeunit) in enumerate(generator) {
239+
for (idx, codeunit) in generator.enumerate() {
240240
switch (idx, codeunit, state) {
241241
case (0, Token.Minus, NumberParsingState.Initial):
242242
numberSign = -1
@@ -300,7 +300,7 @@ extension JSValue {
300300
}
301301

302302
static func parseTrue<S: SequenceType where S.Generator.Element == UInt8>(generator: ReplayableGenerator<S>) -> JSParsingResult {
303-
for (idx, codeunit) in enumerate(generator) {
303+
for (idx, codeunit) in generator.enumerate() {
304304
switch (idx, codeunit) {
305305
case (0, Token.t): continue
306306
case (1, Token.r): continue
@@ -327,7 +327,7 @@ extension JSValue {
327327
}
328328

329329
static func parseFalse<S: SequenceType where S.Generator.Element == UInt8>(generator: ReplayableGenerator<S>) -> JSParsingResult {
330-
for (idx, codeunit) in enumerate(generator) {
330+
for (idx, codeunit) in generator.enumerate() {
331331
switch (idx, codeunit) {
332332
case (0, Token.f): continue
333333
case (1, Token.a): continue
@@ -355,7 +355,7 @@ extension JSValue {
355355
}
356356

357357
static func parseNull<S: SequenceType where S.Generator.Element == UInt8>(generator: ReplayableGenerator<S>) -> JSParsingResult {
358-
for (idx, codeunit) in enumerate(generator) {
358+
for (idx, codeunit) in generator.enumerate() {
359359
switch (idx, codeunit) {
360360
case (0, Token.n): continue
361361
case (1, Token.u): continue
@@ -396,7 +396,7 @@ extension JSValue {
396396
static func parseString<S: SequenceType where S.Generator.Element == UInt8>(generator: ReplayableGenerator<S>, quote: UInt8) -> JSParsingResult {
397397
var bytes = [UInt8]()
398398

399-
for (idx, codeunit) in enumerate(generator) {
399+
for (idx, codeunit) in generator.enumerate() {
400400
switch (idx, codeunit) {
401401
case (0, quote): continue
402402
case (_, quote):
@@ -535,8 +535,8 @@ extension JSValue {
535535

536536
static func exp(number: Double, _ exp: Int) -> Double {
537537
return exp < 0 ?
538-
reduce(0 ..< abs(exp), number, { x, _ in x / 10 }) :
539-
reduce(0 ..< exp, number, { x, _ in x * 10 })
538+
(0 ..< abs(exp)).reduce(number, combine: { x, _ in x / 10 }) :
539+
(0 ..< exp).reduce(number, combine: { x, _ in x * 10 })
540540
}
541541
}
542542

src/JSValue.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,26 @@ extension JSValue {
172172
}
173173
}
174174

175-
extension JSValue : Printable {
175+
extension JSValue : CustomStringConvertible {
176176

177177
/// Attempts to convert the `JSValue` into its string representation.
178178
///
179-
/// :param: indent the indent string to use; defaults to " "
179+
/// - parameter indent: the indent string to use; defaults to " "
180180
///
181-
/// :returns: A `FailableOf<T>` that will contain the `String` value if successful,
181+
/// - returns: A `FailableOf<T>` that will contain the `String` value if successful,
182182
/// otherwise, the `Error` information for the conversion.
183183
public func stringify(indent: String = " ") -> String {
184184
return prettyPrint(indent, 0)
185185
}
186186

187187
/// Attempts to convert the `JSValue` into its string representation.
188188
///
189-
/// :param: indent the number of spaces to include.
189+
/// - parameter indent: the number of spaces to include.
190190
///
191-
/// :returns: A `FailableOf<T>` that will contain the `String` value if successful,
191+
/// - returns: A `FailableOf<T>` that will contain the `String` value if successful,
192192
/// otherwise, the `Error` information for the conversion.
193193
public func stringify(indent: Int) -> String {
194-
let padding = reduce(0..<indent, "") { s, i in return s + " " }
194+
let padding = (0..<indent).reduce("") { s, i in return s + " " }
195195
return prettyPrint(padding, 0)
196196
}
197197

@@ -203,7 +203,7 @@ extension JSValue : Printable {
203203

204204
/// Used to compare two `JSValue` values.
205205
///
206-
/// :returns: `True` when `hasValue` is `true` and the underlying values are the same; `false` otherwise.
206+
/// - returns: `True` when `hasValue` is `true` and the underlying values are the same; `false` otherwise.
207207
public func ==(lhs: JSValue, rhs: JSValue) -> Bool {
208208
switch (lhs.value, rhs.value) {
209209
case (.JSNull, .JSNull):
@@ -231,7 +231,7 @@ public func ==(lhs: JSValue, rhs: JSValue) -> Bool {
231231

232232
extension JSValue {
233233
func prettyPrint(indent: String, _ level: Int) -> String {
234-
let currentIndent = indent == "" ? "" : join(indent, map(0...level, { (item: Int) in "" }))
234+
let currentIndent = indent == "" ? "" : indent.join((0...level).map({ (item: Int) in "" }))
235235
let nextIndent = currentIndent + indent
236236

237237
let newline = indent == "" ? "" : "\n"
@@ -249,10 +249,10 @@ extension JSValue {
249249
return "\"\(escaped)\""
250250

251251
case .JSArray(let array):
252-
return "[\(newline)" + join(",\(newline)", array.map({ "\(nextIndent)\($0.prettyPrint(indent, level + 1))" })) + "\(newline)\(currentIndent)]"
252+
return "[\(newline)" + ",\(newline)".join(array.map({ "\(nextIndent)\($0.prettyPrint(indent, level + 1))" })) + "\(newline)\(currentIndent)]"
253253

254254
case .JSObject(let dict):
255-
return "{\(newline)" + join(",\(newline)", map(dict, { "\(nextIndent)\"\($0)\":\(space)\($1.prettyPrint(indent, level + 1))"})) + "\(newline)\(currentIndent)}"
255+
return "{\(newline)" + ",\(newline)".join(dict.map({ "\(nextIndent)\"\($0)\":\(space)\($1.prettyPrint(indent, level + 1))"})) + "\(newline)\(currentIndent)}"
256256

257257
case .JSNull:
258258
return "null"

src/ReplayableGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public final class ReplayableGenerator<S: SequenceType> : GeneratorType, Sequenc
1919

2020
/// Initializes a new `ReplayableGenerator<S>` with an underlying `SequenceType`.
2121
///
22-
/// :param: sequence the sequence that will be used to traverse the content.
22+
/// - parameter sequence: the sequence that will be used to traverse the content.
2323
public init(_ sequence: S) {
2424
self.generator = sequence.generate()
2525
}

0 commit comments

Comments
 (0)