Skip to content

Commit

Permalink
refactor: added MainActor annotations where needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
TizianoCoroneo committed Jul 18, 2023
1 parent 1c06924 commit 050a1d6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Sources/Deeplink/AnyDeeplink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

/// Type-erased version of ``Deeplink/Deeplink``. Used to keep a list of Deeplinks in the ``Deeplink/DeeplinksCenter`` where every element of the list might have different type parameters.
public struct AnyDeeplink: CustomStringConvertible {
var parseURLIntoInstance: (URL) throws -> Bool
var parseURLIntoInstance: @MainActor (URL) throws -> Bool
public let description: String

/// Designated initializer.
Expand All @@ -21,7 +21,7 @@ public struct AnyDeeplink: CustomStringConvertible {
init<Value>(
deeplink: Deeplink<Value>,
assigningTo instance: Value,
ifMatching completion: @escaping (URL, Value) throws -> Bool
ifMatching completion: @escaping @MainActor (URL, Value) throws -> Bool
) {
self.parseURLIntoInstance = { url in
var newInstance = instance
Expand All @@ -39,7 +39,7 @@ public struct AnyDeeplink: CustomStringConvertible {
/// - completion: The completion handler to invoke if the `URL` passed to the `parse(_ url:)` function matches the deeplink template.
init<Value>(
deeplink: Deeplink<Value>,
ifMatching completion: @escaping (URL, Value) throws -> Bool
ifMatching completion: @escaping @MainActor (URL, Value) throws -> Bool
)
where Value: DefaultInitializable
{
Expand All @@ -55,7 +55,7 @@ extension AnyDeeplink {
/// Attempts to parse the argument `url` using the `deeplink` previously passed to the initializer.
/// If the pattern is recognized successfully, the arguments of the template will get assigned to the `assigningTo` parameter, which will be then forwarded to the `ifMatching` closure, together with the matching `url`.
/// - Parameter url: The `URL` to match.
func parse(
@MainActor func parse(
_ url: URL
) throws -> Bool {
try self.parseURLIntoInstance(url)
Expand Down
10 changes: 5 additions & 5 deletions Sources/Deeplink/DeeplinksCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class DeeplinksCenter {
public func register<Value>(
deeplink: Deeplink<Value>,
assigningTo: Value,
ifMatching completion: @escaping (URL, Value) throws -> Bool
ifMatching completion: @escaping @MainActor (URL, Value) throws -> Bool
) -> DeeplinksCenter {
let typeErasedDeeplink = AnyDeeplink(
deeplink: deeplink,
Expand Down Expand Up @@ -152,7 +152,7 @@ public class DeeplinksCenter {
public func register<Value>(
deeplinks: [Deeplink<Value>],
assigningTo: Value,
ifMatching completion: @escaping (URL, Value) throws -> Bool
ifMatching completion: @escaping @MainActor (URL, Value) throws -> Bool
) -> DeeplinksCenter {

self.deeplinks.append(contentsOf: deeplinks.map {
Expand Down Expand Up @@ -200,7 +200,7 @@ public class DeeplinksCenter {
@discardableResult
public func register(
deeplink: Deeplink<Void>,
ifMatching completion: @escaping (URL) throws -> Bool
ifMatching completion: @escaping @MainActor (URL) throws -> Bool
) -> DeeplinksCenter {
self.register(
deeplink: deeplink,
Expand Down Expand Up @@ -243,7 +243,7 @@ public class DeeplinksCenter {
@discardableResult
public func register(
deeplinks: [Deeplink<Void>],
ifMatching completion: @escaping (URL) throws -> Bool
ifMatching completion: @escaping @MainActor (URL) throws -> Bool
) -> DeeplinksCenter {
self.register(
deeplinks: deeplinks,
Expand All @@ -257,7 +257,7 @@ public class DeeplinksCenter {
/// If a match is found, the corresponding argument segments will be assigned to the keypaths specified in the deeplink interpolation, and the `ifMatching` closure defined when calling `register:` will be executed.
/// If no match is found, an error is thrown.
/// - Parameter url: The `URL` to parse.
public func parse(
@MainActor public func parse(
url: URL
) throws {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
Now we need to make a template that describes how to parse the information from a link.

This time, we'll use a keypath to our `[String]` property, and pass an additional argument to tell the system what separator should we use to parse the arguments.

As before, the data present in the URL at the location where the keypath is inserted will be assigned to the property indicated by the keypath; each item in its own String object.

@Code(name: "Defining Deeplink Data Lists.swift", file: "AddingADeeplinkList 2.swift")
Expand Down
6 changes: 3 additions & 3 deletions Sources/Deeplink/SampleDeeplink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct SampleDeeplink<Value> {
/// - deeplinkTemplate: The deeplink template that you want to test. It is recommended to pass the exact same template instance that you use in your `DeeplinkCenter` to avoid having to manually keep them in sync.
/// - urlToParse: The test URL that you want to use for testing.
/// - assigningToInstance: The instance of the object to which assign the values of the parsed parameters.
/// - expectation: A closure where you should declare an expectation to fulfill, using ``XCTest/XCTestCase/expectation(description:)``.
/// - expectation: A closure where you should declare an expectation to fulfill, using `XCTestCase.expectation(description:)`.
/// - assertions: A closure that you can use to verify the correctness of the parsed parameters.
public init(
deeplinkTemplate: Deeplink<Value>,
Expand Down Expand Up @@ -67,7 +67,7 @@ public extension SampleDeeplink where Value == Void {
/// - Parameters:
/// - deeplinkTemplate: The deeplink template that you want to test. It is recommended to pass the exact same template instance that you use in your `DeeplinkCenter` to avoid having to manually keep them in sync.
/// - urlToParse: The test URL that you want to use for testing.
/// - expectation: A closure where you should declare an expectation to fulfill, using ``XCTest/XCTestCase/expectation(description:)``.
/// - expectation: A closure where you should declare an expectation to fulfill, using `XCTestCase.expectation(description:)`.
init(
deeplinkTemplate: Deeplink<Value>,
urlToParse: URL,
Expand Down Expand Up @@ -102,7 +102,7 @@ public extension DeeplinksCenter {
///
/// See ``SampleDeeplink`` for more information.
/// - Parameter sample: The ``SampleDeeplink`` to test.
func testSampleDeeplink<Value>(
@MainActor func testSampleDeeplink<Value>(
_ sample: SampleDeeplink<Value>
) throws {
guard let anyDeeplinkIndex = self.deeplinks
Expand Down
1 change: 1 addition & 0 deletions Tests/DeeplinkTests/DeeplinkBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fileprivate struct TestData2 {
var arg2: String?
}

@MainActor
class DeeplinkBuilderTests: XCTestCase {

func testFunctionBuilder() throws {
Expand Down
7 changes: 4 additions & 3 deletions Tests/DeeplinkTests/DeeplinksCenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import XCTest
@testable import Deeplink

@MainActor
class DeeplinksCenterTests: XCTestCase {

struct Artist: Equatable {
Expand Down Expand Up @@ -360,7 +361,7 @@ class DeeplinksCenterTests: XCTestCase {
XCTAssertNoThrow(try repo
.parse(url: "https://ticketswap.com/test1/test3"))

waitForExpectations(timeout: 0.1, handler: nil)
waitForExpectations(timeout: 0.01, handler: nil)
}

func testMultipleMatchingLiteralFormatsCallSameClosure() {
Expand Down Expand Up @@ -462,7 +463,7 @@ class DeeplinksCenterTests: XCTestCase {
XCTAssertNoThrow(try repo
.parse(url: url3))

waitForExpectations(timeout: 0.1, handler: nil)
waitForExpectations(timeout: 0.01, handler: nil)
}

func testNoMatchFound() {
Expand Down Expand Up @@ -597,7 +598,7 @@ class DeeplinksCenterTests: XCTestCase {
deeplinkError)
})

waitForExpectations(timeout: 0.1, handler: nil)
waitForExpectations(timeout: 0.01, handler: nil)
}

func testMatchingSuccessDoesNotRollToNextMatches() {
Expand Down

0 comments on commit 050a1d6

Please sign in to comment.