Skip to content

Commit d6f0b01

Browse files
committed
Merge pull request #43 from hyperoslo/feature/config-for-json-serialization
Feature/config for json serialization
2 parents abf3035 + 76bf10b commit d6f0b01

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Source/Shared/Extensions/JSON+Cache.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import Foundation
22

3+
/// A configuration struct
4+
public struct CacheJSONOptions {
5+
/// Options used when creating Foundation objects from JSON data
6+
public static var readingOptions: NSJSONReadingOptions = NSJSONReadingOptions()
7+
/// Options for writing JSON data.
8+
public static var writeOptions: NSJSONWritingOptions = NSJSONWritingOptions()
9+
}
10+
311
// MARK: - Cachable
412

513
/**
614
Implementation of Cachable protocol.
715
*/
16+
817
extension JSON: Cachable {
918

1019
public typealias CacheType = JSON
@@ -20,7 +29,7 @@ extension JSON: Cachable {
2029

2130
do {
2231
let object = try NSJSONSerialization.JSONObjectWithData(data,
23-
options: NSJSONReadingOptions())
32+
options: CacheJSONOptions.readingOptions)
2433

2534
switch object {
2635
case let dictionary as [String : AnyObject]:
@@ -42,6 +51,6 @@ extension JSON: Cachable {
4251
*/
4352
public func encode() -> NSData? {
4453
return try? NSJSONSerialization.dataWithJSONObject(object,
45-
options: NSJSONWritingOptions())
54+
options: CacheJSONOptions.writeOptions)
4655
}
4756
}

0 commit comments

Comments
 (0)