Skip to content

Commit 7d43b9f

Browse files
committed
Implicit cast operator for Range/NSRange
1 parent f26c2f1 commit 7d43b9f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Source/Range.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,14 @@ public class Range/*<Element: ForwardIndexType, Comparable>*/: CustomStringConve
277277
}
278278

279279
#if COCOA
280-
// todo: make a cast operator
280+
public static func __implicit(_ range: Range) -> NSRange {
281+
return range.nativeRange
282+
}
283+
284+
public static func __implicit(_ range: NSRange) -> Range {
285+
return Range(range.location, range.location+range.length, upperBoundClosed: false)
286+
}
287+
281288
public var nativeRange: NSRange {
282289
if let lowerBound = lowerBound, upperBound != nil {
283290
return NSMakeRange(lowerBound, length)

0 commit comments

Comments
 (0)