Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 24 migration, works for OSX and Linux #1

Merged
merged 14 commits into from
Apr 4, 2016
Merged
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
21 changes: 12 additions & 9 deletions Source/LclJSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
**/

#if os(Linux)

import Foundation

public let LclErrorDomain = "Lcl.Error.Domain"
Expand Down Expand Up @@ -48,7 +50,7 @@ public class LclJSONSerialization {
}

let mirror = Mirror(reflecting: obj)
if mirror.displayStyle == .Collection {
if mirror.displayStyle == .collection {
// object is Swift.Array
for element in mirror.children {
guard isValidJSONObjectInternal(element.value) else {
Expand All @@ -57,12 +59,12 @@ public class LclJSONSerialization {
}
return true
}
else if mirror.displayStyle == .Dictionary {
else if mirror.displayStyle == .dictionary {
// object is Swift.Dictionary
for pair in mirror.children {
let pairMirror = Mirror(reflecting: pair.value)
if pairMirror.displayStyle == .Tuple && pairMirror.children.count == 2 {
let generator = pairMirror.children.generate()
if pairMirror.displayStyle == .tuple && pairMirror.children.count == 2 {
let generator = pairMirror.children.makeIterator()
if generator.next()!.value is String {
guard isValidJSONObjectInternal(generator.next()!.value) else {
return false
Expand All @@ -88,7 +90,7 @@ public class LclJSONSerialization {

// top level object must be an Swift.Array or Swift.Dictionary
let mirror = Mirror(reflecting: obj)
guard mirror.displayStyle == .Collection || mirror.displayStyle == .Dictionary else {
guard mirror.displayStyle == .collection || mirror.displayStyle == .dictionary else {
return false
}

Expand Down Expand Up @@ -137,10 +139,10 @@ public class LclJSONSerialization {
}
else {
let mirror = Mirror(reflecting: obj)
if mirror.displayStyle == .Collection {
if mirror.displayStyle == .collection {
try writeJsonArray(mirror.children.map { $0.value as Any }, padding: padding, writer: writer)
}
else if mirror.displayStyle == .Dictionary {
else if mirror.displayStyle == .dictionary {
try writeJsonObject(mirror.children.map { $0.value }, padding: padding, writer: writer)
}
else {
Expand All @@ -161,8 +163,8 @@ public class LclJSONSerialization {
let realComma = NSString(string: ",")
for pair in pairs {
let pairMirror = Mirror(reflecting: pair)
if pairMirror.displayStyle == .Tuple && pairMirror.children.count == 2 {
let generator = pairMirror.children.generate()
if pairMirror.displayStyle == .tuple && pairMirror.children.count == 2 {
let generator = pairMirror.children.makeIterator()
if let key = generator.next()!.value as? String {
let value = generator.next()!.value
writer(comma)
Expand Down Expand Up @@ -233,3 +235,4 @@ public class LclJSONSerialization {
return NSError(domain: LclErrorDomain, code: 1, userInfo: userInfo)
}
}
#endif
Loading