From 19482455ed9529a64e6298f20ba4d2c3dcafd663 Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Sat, 6 Apr 2024 09:01:49 -0400 Subject: [PATCH] Add some missing MainActor annotations --- Sources/Rearrange/UITextRange+Convenience.swift | 10 ++++++---- Tests/RearrangeTests/UITextRangeTests.swift | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) 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()