Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions OptJSON.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
50FCCCA6195C5F2100095152 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastUpgradeCheck = 0600;
TargetAttributes = {
50FCCCAE195C5F2100095152 = {
Expand Down Expand Up @@ -360,10 +361,6 @@
50FCCCC9195C5F2100095152 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -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;
Expand Down
28 changes: 11 additions & 17 deletions OptJSON/OptJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,27 @@
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 }
extension JSONValue {
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 }
}
extension NSNull : JSONValue { }

extension NSString : JSONValue {
public subscript(#key: String) -> JSONValue? { return nil }
public subscript(#index: Int) -> JSONValue? { return nil }
}
extension NSNumber : JSONValue { }

extension NSString : JSONValue { }

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(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 func JSON(object: AnyObject?) -> JSONValue? {
Expand Down
4 changes: 2 additions & 2 deletions OptJSONTests/AltJSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions OptJSONTests/OptJSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down