Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sendable conformance and support for Concurrency #74

Merged
merged 16 commits into from
Oct 17, 2023
Merged

Conversation

AvdLee
Copy link
Contributor

@AvdLee AvdLee commented Oct 11, 2023

This PR is a breaking change and introduces support for Swift Concurrency. There are a few important design decisions I made to keep the code changes at implementation level to a minimum and reduce complexity at call side:

  • UINotificationCenter is unchecked Sendable since all its mutation happens either on the Main Actor or is unlikely going to be in sequence with write operations. I've tried making it a @MainActor, but resulted in difficulties throughout the implementation level. For example, calling UINotificationCenter.current from a non-mainactor init would result in build failures.
  • Since we're queuing notifications, there's no need for the notification center to be accessed on the Main Actor. Presenting happens internally in the framework as triggered from the queue and that part is running on the main actor.
  • In general: wherever it made sense, I've added the @MainActor attribute. Mostly since we're dealing with user interface notifications

Altogether, the result is a thread-safe solution done by using both Swift Concurrency and lock queues. Check out internal comments for additional context.

README.md Show resolved Hide resolved
@wetransferplatform
Copy link
Collaborator

Messages
📖 UINotificationsTests: Executed 25 tests (0 failed, 0 retried, 0 skipped) in 14.958 seconds
📖 Slowest test: UINotificationCenterTests/testCustomDefaultNotificationView() (10.498s)
📖 Slowest test: UINotificationDefaultElementsTests/testEaseOutEaseInPresenter() (2.416s)
📖

View more details on Bitrise

Code Coverage Report

Name Coverage
UINotifications 98.04%

SwiftLint found issues

Severity File Reason
Warning UINotificationDismissTrigger.swift:30 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDurationDismissTrigger.swift:13 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDurationDismissTrigger.swift:15 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDurationDismissTrigger.swift:18 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDurationDismissTrigger.swift:21 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDurationDismissTrigger.swift:34 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:106 Line should be 140 characters or less; currently it has 144 characters (line_length)
Warning UINotification.swift:24 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:30 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:33 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:36 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:46 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:90 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:100 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:105 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:121 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:130 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:133 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:136 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:142 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotification.swift:55 A 'type_property' should not be placed amongst the type content(s) 'subtype' (type_contents_order)
Warning UINotificationCenter.swift:121 Line should be 140 characters or less; currently it has 142 characters (line_length)
Warning UINotificationCenter.swift:84 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationCenter.swift:62 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenter.swift:67 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenter.swift:75 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenter.swift:82 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenter.swift:85 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenter.swift:107 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenter.swift:133 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresenter.swift:17 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresenter.swift:20 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresenter.swift:30 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresenter.swift:33 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresenter.swift:36 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresenter.swift:42 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresenter.swift:45 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationPresentationContext.swift:32 Line should be 140 characters or less; currently it has 145 characters (line_length)
Error UINotificationPresentationContext.swift:67 Line should be 160 characters or less; currently it has 174 characters (line_length)
Error UINotificationPresentationContext.swift:71 Line should be 160 characters or less; currently it has 194 characters (line_length)
Error UINotificationEaseInOutPresenter.swift:35 Line should be 160 characters or less; currently it has 161 characters (line_length)
Warning UINotificationEaseInOutPresenter.swift:48 Parentheses are not needed when declaring closure arguments (unneeded_parentheses_in_closure_argument)
Warning UINotificationEaseInOutPresenter.swift:67 Parentheses are not needed when declaring closure arguments (unneeded_parentheses_in_closure_argument)
Error UINotificationQueue.swift:34 Line should be 160 characters or less; currently it has 168 characters (line_length)
Error UINotificationQueue.swift:42 Line should be 160 characters or less; currently it has 221 characters (line_length)
Error UINotificationQueue.swift:43 Line should be 160 characters or less; currently it has 163 characters (line_length)
Warning UINotificationQueue.swift:45 Parentheses are not needed when declaring closure arguments (unneeded_parentheses_in_closure_argument)
Warning XCTestExtensions.swift:28 Variables should not have redundant type annotation (redundant_type_annotation)
Warning XCTestExtensions.swift:12 Lines should not have trailing whitespace (trailing_whitespace)
Error UINotificationRequest.swift:70 Line should be 160 characters or less; currently it has 190 characters (line_length)
Warning UINotificationRequest.swift:12 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:30 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:33 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:36 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:40 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:43 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:49 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:52 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:77 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:81 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:90 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:94 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationRequest.swift:25 A 'type_property' should not be placed amongst the type content(s) 'subtype' (type_contents_order)
Warning UINotificationCenterTests.swift:45 Line should be 140 characters or less; currently it has 150 characters (line_length)
Warning UINotificationCenterTests.swift:53 Line should be 140 characters or less; currently it has 150 characters (line_length)
Error UINotificationCenterTests.swift:65 Line should be 160 characters or less; currently it has 161 characters (line_length)
Warning UINotificationCenterTests.swift:76 Line should be 140 characters or less; currently it has 149 characters (line_length)
Warning UINotificationCenterTests.swift:10 Imports should be sorted (sorted_imports)
Warning UINotificationCenterTests.swift:11 Imports should be sorted (sorted_imports)
Warning UINotificationCenterTests.swift:15 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenterTests.swift:28 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenterTests.swift:35 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenterTests.swift:47 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenterTests.swift:55 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenterTests.swift:62 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenterTests.swift:67 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationCenterTests.swift:26 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationCenterTests.swift:33 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationTestCase.swift:13 Consider using final for this class, or use a struct (final_class)
Warning UINotificationTestCase.swift:23 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationTestCase.swift:24 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationTestCase.swift:49 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationTestCase.swift:52 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationTestCase.swift:53 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationTestCase.swift:11 Imports should be sorted (sorted_imports)
Warning UINotificationTestCase.swift:15 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:18 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:22 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:25 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:37 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:44 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:46 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:51 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:54 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:59 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:65 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:70 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:73 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:78 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:82 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationTestCase.swift:14 An 'instance_property' should not be placed amongst the type content(s) 'subtype' (type_contents_order)
Warning UINotificationDefaultElementsTests.swift:70 Line should be 140 characters or less; currently it has 156 characters (line_length)
Error UINotificationDefaultElementsTests.swift:92 Line should be 160 characters or less; currently it has 213 characters (line_length)
Error UINotificationDefaultElementsTests.swift:107 Line should be 160 characters or less; currently it has 214 characters (line_length)
Error UINotificationDefaultElementsTests.swift:122 Line should be 160 characters or less; currently it has 207 characters (line_length)
Error UINotificationDefaultElementsTests.swift:136 Line should be 160 characters or less; currently it has 164 characters (line_length)
Warning UINotificationDefaultElementsTests.swift:142 Line should be 140 characters or less; currently it has 158 characters (line_length)
Error UINotificationDefaultElementsTests.swift:154 Line should be 160 characters or less; currently it has 171 characters (line_length)
Error UINotificationDefaultElementsTests.swift:159 Line should be 160 characters or less; currently it has 164 characters (line_length)
Error UINotificationDefaultElementsTests.swift:163 Line should be 160 characters or less; currently it has 261 characters (line_length)
Error UINotificationDefaultElementsTests.swift:164 Line should be 160 characters or less; currently it has 267 characters (line_length)
Warning UINotificationDefaultElementsTests.swift:18 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultElementsTests.swift:19 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultElementsTests.swift:20 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultElementsTests.swift:21 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultElementsTests.swift:22 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultElementsTests.swift:27 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultElementsTests.swift:24 Use shorthand syntax for optional binding (shorthand_optional_binding)
Warning UINotificationDefaultElementsTests.swift:10 Imports should be sorted (sorted_imports)
Warning UINotificationDefaultElementsTests.swift:11 Imports should be sorted (sorted_imports)
Warning UINotificationDefaultElementsTests.swift:29 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:53 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:56 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:69 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:75 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:79 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:89 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:91 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:94 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:104 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:106 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:133 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:139 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:144 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:153 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:157 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultElementsTests.swift:68 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultElementsTests.swift:74 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultElementsTests.swift:77 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultElementsTests.swift:137 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultElementsTests.swift:138 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultElementsTests.swift:154 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultElementsTests.swift:163 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultElementsTests.swift:164 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Error UINotificationDefaultViewTests.swift:29 Line should be 160 characters or less; currently it has 371 characters (line_length)
Error UINotificationDefaultViewTests.swift:43 Line should be 160 characters or less; currently it has 371 characters (line_length)
Error UINotificationDefaultViewTests.swift:55 Line should be 160 characters or less; currently it has 366 characters (line_length)
Warning UINotificationDefaultViewTests.swift:59 Line should be 140 characters or less; currently it has 148 characters (line_length)
Warning UINotificationDefaultViewTests.swift:62 Line should be 140 characters or less; currently it has 148 characters (line_length)
Warning UINotificationDefaultViewTests.swift:69 Line should be 140 characters or less; currently it has 143 characters (line_length)
Warning UINotificationDefaultViewTests.swift:79 Line should be 140 characters or less; currently it has 145 characters (line_length)
Warning UINotificationDefaultViewTests.swift:84 Line should be 140 characters or less; currently it has 144 characters (line_length)
Warning UINotificationDefaultViewTests.swift:116 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultViewTests.swift:117 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultViewTests.swift:118 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultViewTests.swift:119 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultViewTests.swift:120 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultViewTests.swift:121 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultViewTests.swift:126 Variables should not have redundant type annotation (redundant_type_annotation)
Warning UINotificationDefaultViewTests.swift:10 Imports should be sorted (sorted_imports)
Warning UINotificationDefaultViewTests.swift:11 Imports should be sorted (sorted_imports)
Warning UINotificationDefaultViewTests.swift:15 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:32 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:35 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:45 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:51 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:57 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:60 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:63 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:66 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:71 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:75 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:78 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:87 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:91 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:99 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:105 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:112 Lines should not have trailing whitespace (trailing_whitespace)
Warning UINotificationDefaultViewTests.swift:47 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:49 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:59 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:62 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:65 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:69 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:76 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:77 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:83 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:84 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
Warning UINotificationDefaultViewTests.swift:85 Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)

Generated by 🚫 Danger Swift against c7a652d

Copy link
Member

@raphkoebraam raphkoebraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link
Contributor

@BasThomas BasThomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 nice work!

README.md Show resolved Hide resolved
Sources/UINotificationQueue.swift Show resolved Hide resolved
@AvdLee AvdLee merged commit f57bed0 into master Oct 17, 2023
2 checks passed
@AvdLee AvdLee deleted the feature/sendable branch October 17, 2023 11:13
@wetransferplatform
Copy link
Collaborator

Congratulations! 🎉 This was released as part of Release 2.0.0 🚀

Generated by GitBuddy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants