Skip to content

Commit

Permalink
Merge pull request #14 from mddub/swift-updates
Browse files Browse the repository at this point in the history
Swift 4 support
  • Loading branch information
mddub authored Jul 27, 2017
2 parents 72b370f + aad8a8e commit e09c16f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ShareClient/ShareClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,14 @@ public class ShareClient {

private func parseDate(_ wt: String) throws -> Date {
// wt looks like "/Date(1462404576000)/"
let re = try NSRegularExpression(pattern: "\\((.*)\\)", options: [])
if let match = re.firstMatch(in: wt, options: [], range: NSMakeRange(0, wt.characters.count)) {
let epoch = Double((wt as NSString).substring(with: match.rangeAt(1)))! / 1000
let re = try NSRegularExpression(pattern: "\\((.*)\\)")
if let match = re.firstMatch(in: wt, range: NSMakeRange(0, wt.characters.count)) {
#if swift(>=4)
let matchRange = match.range(at: 1)
#else
let matchRange = match.rangeAt(1)
#endif
let epoch = Double((wt as NSString).substring(with: matchRange))! / 1000
return Date(timeIntervalSince1970: epoch)
} else {
throw ShareError.dateError
Expand Down

0 comments on commit e09c16f

Please sign in to comment.