From 053788617a2772965581b865e1823b98203e5df0 Mon Sep 17 00:00:00 2001 From: Andrew Podkovyrin Date: Fri, 25 Sep 2015 12:57:44 +0300 Subject: [PATCH 1/2] Converted to Swift 2.0 syntax --- OptJSON.xcodeproj/project.pbxproj | 9 +-------- OptJSON/OptJSON.swift | 24 ++++++++++++------------ OptJSONTests/AltJSONTests.swift | 4 ++-- OptJSONTests/OptJSONTests.swift | 4 ++-- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/OptJSON.xcodeproj/project.pbxproj b/OptJSON.xcodeproj/project.pbxproj index 24ed686..36e0a78 100644 --- a/OptJSON.xcodeproj/project.pbxproj +++ b/OptJSON.xcodeproj/project.pbxproj @@ -164,6 +164,7 @@ 50FCCCA6195C5F2100095152 /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0700; LastUpgradeCheck = 0600; TargetAttributes = { 50FCCCAE195C5F2100095152 = { @@ -360,10 +361,6 @@ 50FCCCC9195C5F2100095152 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -378,10 +375,6 @@ 50FCCCCA195C5F2100095152 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); INFOPLIST_FILE = OptJSONTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; diff --git a/OptJSON/OptJSON.swift b/OptJSON/OptJSON.swift index b1d6f30..70807f7 100644 --- a/OptJSON/OptJSON.swift +++ b/OptJSON/OptJSON.swift @@ -9,33 +9,33 @@ import Foundation public protocol JSONValue { - subscript(#key: String) -> JSONValue? { get } - subscript(#index: Int) -> JSONValue? { get } + subscript(key key: String) -> JSONValue? { get } + subscript(index index: Int) -> JSONValue? { get } } extension NSNull : JSONValue { - public subscript(#key: String) -> JSONValue? { return nil } - public subscript(#index: Int) -> JSONValue? { return nil } + public subscript(key key: String) -> JSONValue? { return nil } + public subscript(index index: Int) -> JSONValue? { return nil } } extension NSNumber : JSONValue { - public subscript(#key: String) -> JSONValue? { return nil } - public subscript(#index: Int) -> JSONValue? { return nil } + public subscript(key key: String) -> JSONValue? { return nil } + public subscript(index index: Int) -> JSONValue? { return nil } } extension NSString : JSONValue { - public subscript(#key: String) -> JSONValue? { return nil } - public subscript(#index: Int) -> JSONValue? { return nil } + public subscript(key key: String) -> JSONValue? { return nil } + public subscript(index index: Int) -> JSONValue? { return nil } } extension NSArray : JSONValue { - public subscript(#key: String) -> JSONValue? { return nil } - public subscript(#index: Int) -> JSONValue? { return index < count && index >= 0 ? JSON(self[index]) : nil } + public subscript(key key: String) -> JSONValue? { return nil } + public subscript(index index: Int) -> JSONValue? { return index < count && index >= 0 ? JSON(self[index]) : nil } } extension NSDictionary : JSONValue { - public subscript(#key: String) -> JSONValue? { return JSON(self[key]) } - public subscript(#index: Int) -> JSONValue? { return nil } + public subscript(key key: String) -> JSONValue? { return JSON(self[key]) } + public subscript(index index: Int) -> JSONValue? { return nil } } public func JSON(object: AnyObject?) -> JSONValue? { diff --git a/OptJSONTests/AltJSONTests.swift b/OptJSONTests/AltJSONTests.swift index 57db260..b8a0972 100644 --- a/OptJSONTests/AltJSONTests.swift +++ b/OptJSONTests/AltJSONTests.swift @@ -52,8 +52,8 @@ let altJSON : AltJSON = [ class AltJSONTests: XCTestCase { let nsJSON : AnyObject! = { - let data = NSJSONSerialization.dataWithJSONObject(altJSON, options: NSJSONWritingOptions(0), error: nil) - return NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions(0), error: nil) + let data = try? NSJSONSerialization.dataWithJSONObject(altJSON, options: NSJSONWritingOptions(rawValue: 0)) + return try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions(rawValue: 0)) }() func testBaseTypes() { diff --git a/OptJSONTests/OptJSONTests.swift b/OptJSONTests/OptJSONTests.swift index 958cd09..5e6553e 100644 --- a/OptJSONTests/OptJSONTests.swift +++ b/OptJSONTests/OptJSONTests.swift @@ -33,8 +33,8 @@ let nativeJSON = [ class OptJSONTests: XCTestCase { let nsJSON : AnyObject! = { - let data = NSJSONSerialization.dataWithJSONObject(nativeJSON, options: NSJSONWritingOptions(0), error: nil) - return NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions(0), error: nil) + let data = try? NSJSONSerialization.dataWithJSONObject(nativeJSON, options: NSJSONWritingOptions(rawValue: 0)) + return try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions(rawValue: 0)) }() func testBaseTypes() { From a843ac8b92fb37628f7cf8b9dd88c10f89b7c5b3 Mon Sep 17 00:00:00 2001 From: Andrew Podkovyrin Date: Fri, 25 Sep 2015 13:04:17 +0300 Subject: [PATCH 2/2] Used protocol extenstions --- OptJSON/OptJSON.swift | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/OptJSON/OptJSON.swift b/OptJSON/OptJSON.swift index 70807f7..3456fea 100644 --- a/OptJSON/OptJSON.swift +++ b/OptJSON/OptJSON.swift @@ -13,29 +13,23 @@ public protocol JSONValue { subscript(index index: Int) -> JSONValue? { get } } -extension NSNull : JSONValue { +extension JSONValue { public subscript(key key: String) -> JSONValue? { return nil } public subscript(index index: Int) -> JSONValue? { return nil } } -extension NSNumber : JSONValue { - public subscript(key key: String) -> JSONValue? { return nil } - public subscript(index index: Int) -> JSONValue? { return nil } -} +extension NSNull : JSONValue { } -extension NSString : JSONValue { - public subscript(key key: String) -> JSONValue? { return nil } - public subscript(index index: Int) -> JSONValue? { return nil } -} +extension NSNumber : JSONValue { } + +extension NSString : JSONValue { } extension NSArray : JSONValue { - public subscript(key key: String) -> JSONValue? { return nil } public subscript(index index: Int) -> JSONValue? { return index < count && index >= 0 ? JSON(self[index]) : nil } } extension NSDictionary : JSONValue { public subscript(key key: String) -> JSONValue? { return JSON(self[key]) } - public subscript(index index: Int) -> JSONValue? { return nil } } public func JSON(object: AnyObject?) -> JSONValue? {