From b9781be25244474576eee828822250df98fb1022 Mon Sep 17 00:00:00 2001 From: Tristan Himmelman Date: Sun, 3 Jan 2016 20:47:18 -0400 Subject: [PATCH] - made toJSONString a public static function --- ObjectMapper/Core/Mapper.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ObjectMapper/Core/Mapper.swift b/ObjectMapper/Core/Mapper.swift index c8502c12..f2c20f18 100755 --- a/ObjectMapper/Core/Mapper.swift +++ b/ObjectMapper/Core/Mapper.swift @@ -325,22 +325,22 @@ extension Mapper { public func toJSONString(object: N, prettyPrint: Bool = false) -> String? { let JSONDict = toJSON(object) - return toJSONString(JSONDict, prettyPrint: prettyPrint) + return Mapper.toJSONString(JSONDict, prettyPrint: prettyPrint) } /// Maps an array of Objects to a JSON string with option of pretty formatting public func toJSONString(array: [N], prettyPrint: Bool = false) -> String? { let JSONDict = toJSONArray(array) - return toJSONString(JSONDict, prettyPrint: prettyPrint) + return Mapper.toJSONString(JSONDict, prettyPrint: prettyPrint) } - private func toJSONString(object: AnyObject, prettyPrint: Bool) -> String? { - if NSJSONSerialization.isValidJSONObject(object) { - let options: NSJSONWritingOptions = prettyPrint ? .PrettyPrinted : [] + public static func toJSONString(JSONObject: AnyObject, prettyPrint: Bool) -> String? { + if NSJSONSerialization.isValidJSONObject(JSONObject) { let JSONData: NSData? do { - JSONData = try NSJSONSerialization.dataWithJSONObject(object, options: options) + let options: NSJSONWritingOptions = prettyPrint ? .PrettyPrinted : [] + JSONData = try NSJSONSerialization.dataWithJSONObject(JSONObject, options: options) } catch let error { print(error) JSONData = nil @@ -400,7 +400,7 @@ extension Mapper where N: Hashable { public func toJSONString(set: Set, prettyPrint: Bool = false) -> String? { let JSONDict = toJSONSet(set) - return toJSONString(JSONDict, prettyPrint: prettyPrint) + return Mapper.toJSONString(JSONDict, prettyPrint: prettyPrint) } }