-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to simplify range/position abstractions with the Bounded prot…
…ocol
- Loading branch information
1 parent
5dc217e
commit fb90945
Showing
6 changed files
with
86 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public protocol Bounded<Bound> { | ||
associatedtype Bound | ||
|
||
var lowerBound: Bound { get } | ||
var upperBound: Bound { get } | ||
} | ||
|
||
#if os(macOS) | ||
import AppKit | ||
#elseif canImport(UIKit) | ||
import UIKit | ||
#endif | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, macCatalyst 15.0, *) | ||
extension NSTextRange : Bounded { | ||
public var lowerBound: NSTextLocation { location } | ||
public var upperBound: NSTextLocation { endLocation } | ||
} | ||
|
||
extension TextRange : Bounded { | ||
public nonisolated var lowerBound: TextPosition { | ||
MainActor.assumeIsolated { start } | ||
} | ||
|
||
public nonisolated var upperBound: TextPosition { | ||
MainActor.assumeIsolated { end } | ||
} | ||
} | ||
|
||
extension NSRange : Bounded {} | ||
|
||
extension Range : Bounded {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters