Skip to content

Commit

Permalink
- made toJSONString a public static function
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanhimmelman committed Jan 4, 2016
1 parent 50e9493 commit b9781be
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ObjectMapper/Core/Mapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -400,7 +400,7 @@ extension Mapper where N: Hashable {
public func toJSONString(set: Set<N>, prettyPrint: Bool = false) -> String? {
let JSONDict = toJSONSet(set)

return toJSONString(JSONDict, prettyPrint: prettyPrint)
return Mapper.toJSONString(JSONDict, prettyPrint: prettyPrint)
}
}

Expand Down

0 comments on commit b9781be

Please sign in to comment.