Skip to content

Commit e1ce8d3

Browse files
author
Eric Wu
committed
增加api
1 parent 1e1bda9 commit e1ce8d3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

CRBoostSwift/Classes/CRMath.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,16 @@ public func CRUUIDString() -> String {
420420
return NSUUID().uuidString
421421
}
422422

423+
// MARK: - timer
424+
425+
public func CRStopTimer(_ tmr: Timer?) {
426+
if let timer = tmr {
427+
if timer.isValid {
428+
timer.invalidate()
429+
}
430+
}
431+
}
432+
423433
// MARK: - GCD
424434

425435
public func CRRunOnMainThread(task: @escaping CRVoidBlock) {

CRBoostSwift/Classes/Foundation+CRBoost.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ extension String {
124124
return result
125125
}
126126

127+
@discardableResult
128+
public func safeRemoveFirst(_ k: Int = 1) -> String {
129+
if count < k {
130+
return self
131+
}
132+
var result = self
133+
result.removeFirst(k)
134+
return result
135+
}
136+
137+
@discardableResult
138+
public func safeRemoveLast(_ k: Int = 1) -> String {
139+
if count < k {
140+
return self
141+
}
142+
var result = self
143+
result.removeLast(k)
144+
return result
145+
}
146+
127147
@discardableResult
128148
public func retainDecimal(_ digits: Int) -> String {
129149
let formatter = NumberFormatter()

0 commit comments

Comments
 (0)