diff --git a/Sources/Rearrange/UITextRange+Convenience.swift b/Sources/Rearrange/UITextRange+Convenience.swift index 5e6e7d0..f6697ac 100644 --- a/Sources/Rearrange/UITextRange+Convenience.swift +++ b/Sources/Rearrange/UITextRange+Convenience.swift @@ -1,8 +1,9 @@ #if os(iOS) || os(tvOS) || os(visionOS) import UIKit -public extension NSRange { - init?(_ textRange: UITextRange, textView: UITextView) { +extension NSRange { + @MainActor + public init?(_ textRange: UITextRange, textView: UITextView) { let location = textView.offset(from: textView.beginningOfDocument, to: textRange.start) let length = textView.offset(from: textRange.start, to: textRange.end) @@ -14,8 +15,9 @@ public extension NSRange { } } -public extension UITextView { - func textRange(with range: NSRange) -> UITextRange? { +extension UITextView { + @MainActor + public func textRange(with range: NSRange) -> UITextRange? { guard let start = position(from: beginningOfDocument, offset: range.location) else { return nil } diff --git a/Tests/RearrangeTests/UITextRangeTests.swift b/Tests/RearrangeTests/UITextRangeTests.swift index d5e3255..db203a2 100644 --- a/Tests/RearrangeTests/UITextRangeTests.swift +++ b/Tests/RearrangeTests/UITextRangeTests.swift @@ -4,6 +4,7 @@ import Rearrange import UIKit final class UITextRangeTests: XCTestCase { + @MainActor func testTextRangeWithRange() throws { let view = UITextView() @@ -15,6 +16,7 @@ final class UITextRangeTests: XCTestCase { XCTAssertEqual(textRange, fullRange) } + @MainActor func testRangeWithTextRange() throws { let view = UITextView()