Skip to content

Commit

Permalink
Swift 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
fanwar committed Sep 9, 2015
1 parent ea01ef6 commit c309424
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions JSONHelper/JSONHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public func <-- <T>(inout property: T?, value: AnyObject?) -> T? {
switch property {
case is Int?:
if unwrappedValue is String {
if let intValue = "\(unwrappedValue)".toInt() {
if let intValue = Int("\(unwrappedValue)") {
newValue = intValue as? T
}
}
Expand Down Expand Up @@ -509,9 +509,13 @@ public func <-- <T: RawRepresentable>(inout property: T, value: AnyObject?) -> T
// MARK: JSON String Deserialization

private func dataStringToObject(dataString: String) -> AnyObject? {
var data: NSData = dataString.dataUsingEncoding(NSUTF8StringEncoding)!
var error: NSError?
return NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: &error)
let data: NSData = dataString.dataUsingEncoding(NSUTF8StringEncoding)!
do {
let jsonObject = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0))
return jsonObject
} catch {
return nil
}
}

public func <-- <T: Deserializable>(inout instance: T?, dataString: String) -> T? {
Expand Down

0 comments on commit c309424

Please sign in to comment.