From 2ce6ec5db506f86675599532fa3dbfa1af5ee7cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zhiyu=20Zhu/=E6=9C=B1=E6=99=BA=E8=AF=AD?= Date: Fri, 5 Apr 2019 15:02:15 -0400 Subject: [PATCH] Use NSRange properly --- Sources/Schedule/Period.swift | 2 +- Sources/Schedule/Time.swift | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/Schedule/Period.swift b/Sources/Schedule/Period.swift index f2836e3..d1a0a98 100644 --- a/Sources/Schedule/Period.swift +++ b/Sources/Schedule/Period.swift @@ -72,7 +72,7 @@ public struct Period { let mark: Character = "秋" str = regexp.stringByReplacingMatches( in: str, - range: NSRange(location: 0, length: str.count), + range: NSRange(str.startIndex..., in: str), withTemplate: String(mark) ) diff --git a/Sources/Schedule/Time.swift b/Sources/Schedule/Time.swift index 2268d55..76d35e7 100644 --- a/Sources/Schedule/Time.swift +++ b/Sources/Schedule/Time.swift @@ -50,10 +50,11 @@ public struct Time { // swiftlint:disable force_try let regexp = try! NSRegularExpression(pattern: pattern, options: []) + let nsString = NSString(string: string) guard let matches = regexp.matches( in: string, options: [], - range: NSRange(location: 0, length: string.count)).first + range: NSRange(location: 0, length: nsString.length)).first else { return nil } @@ -65,7 +66,7 @@ public struct Time { for i in 0..