Skip to content

Commit 83c6ff8

Browse files
authored
Add NS_SWIFT_UI_ACTOR to methods always called on main (#2121)
* Add NS_SWIFT_UI_ACTOR to methods always called on main * found a couple more main actor blocks/methods
1 parent 2d7bf71 commit 83c6ff8

15 files changed

+94
-92
lines changed

Source/ASCellNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
133133
* The backing view controller, or @c nil if the node wasn't initialized with backing view controller
134134
* @note This property must be accessed on the main thread.
135135
*/
136-
@property (nullable, nonatomic, readonly) UIViewController *viewController;
136+
@property (nullable, nonatomic, readonly) UIViewController *viewController NS_SWIFT_UI_ACTOR;
137137

138138

139139
/**

Source/ASCollectionNode+Beta.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626
/**
2727
* The elements that are currently displayed. The "UIKit index space". Must be accessed on main thread.
2828
*/
29-
@property (nonatomic, readonly) ASElementMap *visibleElements;
29+
@property (nonatomic, readonly) ASElementMap *visibleElements NS_SWIFT_UI_ACTOR;
3030

3131
@property (nullable, readonly) id<ASCollectionLayoutDelegate> layoutDelegate;
3232

@@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
6262
*
6363
* When isSynchronized == YES, the block is run block immediately (before the method returns).
6464
*/
65-
- (void)onDidFinishSynchronizing:(void (^)(void))didFinishSynchronizing;
65+
- (void)onDidFinishSynchronizing:(NS_SWIFT_UI_ACTOR void (^)(void))didFinishSynchronizing;
6666

6767
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout layoutFacilitator:(nullable id<ASCollectionViewLayoutFacilitatorProtocol>)layoutFacilitator;
6868

Source/ASCollectionNode.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ NS_ASSUME_NONNULL_BEGIN
226226
*
227227
* This method must be called on the main thread.
228228
*/
229-
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;
229+
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated NS_SWIFT_UI_ACTOR;
230230

231231
/**
232232
* Determines collection node's current scroll direction. Supports 2-axis collection nodes.
@@ -266,7 +266,7 @@ NS_ASSUME_NONNULL_BEGIN
266266
* Boolean parameter that contains the value YES if all of the related animations completed successfully or
267267
* NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
268268
*/
269-
- (void)performBatchAnimated:(BOOL)animated updates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable void (^)(BOOL finished))completion;
269+
- (void)performBatchAnimated:(BOOL)animated updates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable NS_SWIFT_UI_ACTOR void (^)(BOOL finished))completion NS_SWIFT_UI_ACTOR;
270270

271271
/**
272272
* Perform a batch of updates asynchronously, optionally disabling all animations in the batch. This method must be called from the main thread.
@@ -277,7 +277,7 @@ NS_ASSUME_NONNULL_BEGIN
277277
* Boolean parameter that contains the value YES if all of the related animations completed successfully or
278278
* NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
279279
*/
280-
- (void)performBatchUpdates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable void (^)(BOOL finished))completion;
280+
- (void)performBatchUpdates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable void (^)(BOOL finished))completion NS_SWIFT_UI_ACTOR;
281281

282282
/**
283283
* Returns YES if the ASCollectionNode is still processing changes from performBatchUpdates:.
@@ -306,7 +306,7 @@ NS_ASSUME_NONNULL_BEGIN
306306
*
307307
* Calling -waitUntilAllUpdatesAreProcessed is one way to flush any pending update completion blocks.
308308
*/
309-
- (void)onDidFinishProcessingUpdates:(void (^)(void))didFinishProcessingUpdates;
309+
- (void)onDidFinishProcessingUpdates:(NS_SWIFT_UI_ACTOR void (^)(void))didFinishProcessingUpdates;
310310

311311
/**
312312
* Blocks execution of the main thread until all section and item updates are committed to the view. This method must be called from the main thread.
@@ -321,7 +321,7 @@ NS_ASSUME_NONNULL_BEGIN
321321
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
322322
* before this method is called.
323323
*/
324-
- (void)insertSections:(NSIndexSet *)sections;
324+
- (void)insertSections:(NSIndexSet *)sections NS_SWIFT_UI_ACTOR;
325325

326326
/**
327327
* Deletes one or more sections.
@@ -331,7 +331,7 @@ NS_ASSUME_NONNULL_BEGIN
331331
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
332332
* before this method is called.
333333
*/
334-
- (void)deleteSections:(NSIndexSet *)sections;
334+
- (void)deleteSections:(NSIndexSet *)sections NS_SWIFT_UI_ACTOR;
335335

336336
/**
337337
* Reloads the specified sections.
@@ -341,7 +341,7 @@ NS_ASSUME_NONNULL_BEGIN
341341
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
342342
* before this method is called.
343343
*/
344-
- (void)reloadSections:(NSIndexSet *)sections;
344+
- (void)reloadSections:(NSIndexSet *)sections NS_SWIFT_UI_ACTOR;
345345

346346
/**
347347
* Moves a section to a new location.
@@ -353,7 +353,7 @@ NS_ASSUME_NONNULL_BEGIN
353353
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
354354
* before this method is called.
355355
*/
356-
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;
356+
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection NS_SWIFT_UI_ACTOR;
357357

358358
/**
359359
* Inserts items at the locations identified by an array of index paths.
@@ -363,7 +363,7 @@ NS_ASSUME_NONNULL_BEGIN
363363
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
364364
* before this method is called.
365365
*/
366-
- (void)insertItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
366+
- (void)insertItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_SWIFT_UI_ACTOR;
367367

368368
/**
369369
* Deletes the items specified by an array of index paths.
@@ -373,7 +373,7 @@ NS_ASSUME_NONNULL_BEGIN
373373
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
374374
* before this method is called.
375375
*/
376-
- (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
376+
- (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_SWIFT_UI_ACTOR;
377377

378378
/**
379379
* Reloads the specified items.
@@ -383,7 +383,7 @@ NS_ASSUME_NONNULL_BEGIN
383383
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
384384
* before this method is called.
385385
*/
386-
- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
386+
- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_SWIFT_UI_ACTOR;
387387

388388
/**
389389
* Moves the item at a specified location to a destination location.
@@ -395,7 +395,7 @@ NS_ASSUME_NONNULL_BEGIN
395395
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
396396
* before this method is called.
397397
*/
398-
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;
398+
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath NS_SWIFT_UI_ACTOR;
399399

400400
/**
401401
* Reload everything from scratch, destroying the working range and all cached nodes.
@@ -404,7 +404,7 @@ NS_ASSUME_NONNULL_BEGIN
404404
* the main thread.
405405
* @warning This method is substantially more expensive than UICollectionView's version.
406406
*/
407-
- (void)reloadDataWithCompletion:(nullable void (^)(void))completion;
407+
- (void)reloadDataWithCompletion:(nullable NS_SWIFT_UI_ACTOR void (^)(void))completion;
408408

409409

410410
/**
@@ -441,7 +441,7 @@ NS_ASSUME_NONNULL_BEGIN
441441
*
442442
* @discussion This method must be called from the main thread.
443443
*/
444-
- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition;
444+
- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition NS_SWIFT_UI_ACTOR;
445445

446446
/**
447447
* Deselects the item at the specified index.
@@ -454,7 +454,7 @@ NS_ASSUME_NONNULL_BEGIN
454454
*
455455
* @discussion This method must be called from the main thread.
456456
*/
457-
- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
457+
- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated NS_SWIFT_UI_ACTOR;
458458

459459
#pragma mark - Querying Data
460460

@@ -477,7 +477,7 @@ NS_ASSUME_NONNULL_BEGIN
477477
*
478478
* @return an array containing the nodes being displayed on screen. This must be called on the main thread.
479479
*/
480-
@property (nonatomic, readonly) NSArray<__kindof ASCellNode *> *visibleNodes;
480+
@property (nonatomic, readonly) NSArray<__kindof ASCellNode *> *visibleNodes NS_SWIFT_UI_ACTOR;
481481

482482
/**
483483
* Retrieves the node for the item at the given index path.
@@ -513,7 +513,7 @@ NS_ASSUME_NONNULL_BEGIN
513513
*
514514
* @return an array containing the index paths of all visible items. This must be called on the main thread.
515515
*/
516-
@property (nonatomic, readonly) NSArray<NSIndexPath *> *indexPathsForVisibleItems;
516+
@property (nonatomic, readonly) NSArray<NSIndexPath *> *indexPathsForVisibleItems NS_SWIFT_UI_ACTOR;
517517

518518
/**
519519
* Retrieve the index path of the item at the given point.
@@ -522,7 +522,7 @@ NS_ASSUME_NONNULL_BEGIN
522522
*
523523
* @return The indexPath for the item at the given point. This must be called on the main thread.
524524
*/
525-
- (nullable NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point AS_WARN_UNUSED_RESULT;
525+
- (nullable NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point AS_WARN_UNUSED_RESULT NS_SWIFT_UI_ACTOR;
526526

527527
/**
528528
* Retrieve the cell at the given index path.
@@ -531,7 +531,7 @@ NS_ASSUME_NONNULL_BEGIN
531531
*
532532
* @return The cell for the given index path. This must be called on the main thread.
533533
*/
534-
- (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath;
534+
- (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath NS_SWIFT_UI_ACTOR;
535535

536536
/**
537537
* Retrieves the context object for the given section, as provided by the data source in
@@ -610,7 +610,7 @@ NS_ASSUME_NONNULL_BEGIN
610610
* not implement reuse (it will be called once per item). Unlike UICollectionView's version,
611611
* this method is not called when the item is about to display.
612612
*/
613-
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath;
613+
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath NS_SWIFT_UI_ACTOR;
614614

615615
/**
616616
* Asks the data source to provide a node-block to display for the given supplementary element in the collection view.

Source/ASCollectionView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
7979
*
8080
* @return The context object, or @c nil if no context was provided.
8181
*/
82-
- (nullable id<ASSectionContext>)contextForSection:(NSInteger)section AS_WARN_UNUSED_RESULT;
82+
- (nullable id<ASSectionContext>)contextForSection:(NSInteger)section AS_WARN_UNUSED_RESULT NS_SWIFT_UI_ACTOR;
8383

8484
@end
8585

Source/ASDisplayNode+Convenience.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
2121
* @warning This property may only be accessed on the main thread. This property may
2222
* be @c nil until the node's view is actually hosted in the view hierarchy.
2323
*/
24-
@property (nonatomic, nullable, readonly) __kindof UIViewController *closestViewController;
24+
@property (nonatomic, nullable, readonly) __kindof UIViewController *closestViewController NS_SWIFT_UI_ACTOR;
2525

2626
@end
2727

Source/ASDisplayNode+InterfaceState.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,63 +46,63 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
4646
* @discussion Subclasses may use this to monitor when they become visible, should free cached data, and much more.
4747
* @see ASInterfaceState
4848
*/
49-
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState;
49+
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState NS_SWIFT_UI_ACTOR;
5050

5151
/**
5252
* @abstract Called whenever the node becomes visible.
5353
* @discussion Subclasses may use this to monitor when they become visible.
5454
* @note This method is guaranteed to be called on main.
5555
*/
56-
- (void)didEnterVisibleState;
56+
- (void)didEnterVisibleState NS_SWIFT_UI_ACTOR;
5757

5858
/**
5959
* @abstract Called whenever the node is no longer visible.
6060
* @discussion Subclasses may use this to monitor when they are no longer visible.
6161
* @note This method is guaranteed to be called on main.
6262
*/
63-
- (void)didExitVisibleState;
63+
- (void)didExitVisibleState NS_SWIFT_UI_ACTOR;
6464

6565
/**
6666
* @abstract Called whenever the the node has entered the display state.
6767
* @discussion Subclasses may use this to monitor when a node should be rendering its content.
6868
* @note This method is guaranteed to be called on main.
6969
*/
70-
- (void)didEnterDisplayState;
70+
- (void)didEnterDisplayState NS_SWIFT_UI_ACTOR;
7171

7272
/**
7373
* @abstract Called whenever the the node has exited the display state.
7474
* @discussion Subclasses may use this to monitor when a node should no longer be rendering its content.
7575
* @note This method is guaranteed to be called on main.
7676
*/
77-
- (void)didExitDisplayState;
77+
- (void)didExitDisplayState NS_SWIFT_UI_ACTOR;
7878

7979
/**
8080
* @abstract Called whenever the the node has entered the preload state.
8181
* @discussion Subclasses may use this to monitor data for a node should be preloaded, either from a local or remote source.
8282
* @note This method is guaranteed to be called on main.
8383
*/
84-
- (void)didEnterPreloadState;
84+
- (void)didEnterPreloadState NS_SWIFT_UI_ACTOR;
8585

8686
/**
8787
* @abstract Called whenever the the node has exited the preload state.
8888
* @discussion Subclasses may use this to monitor whether preloading data for a node should be canceled.
8989
* @note This method is guaranteed to be called on main.
9090
*/
91-
- (void)didExitPreloadState;
91+
- (void)didExitPreloadState NS_SWIFT_UI_ACTOR;
9292

9393
/**
9494
* @abstract Called when the node has completed applying the layout.
9595
* @discussion Can be used for operations that are performed after layout has completed.
9696
* @note This method is guaranteed to be called on main.
9797
*/
98-
- (void)nodeDidLayout;
98+
- (void)nodeDidLayout NS_SWIFT_UI_ACTOR;
9999

100100
/**
101101
* @abstract Called when the node loads.
102102
* @discussion Can be used for operations that are performed after the node's view is available.
103103
* @note This method is guaranteed to be called on main.
104104
*/
105-
- (void)nodeDidLoad;
105+
- (void)nodeDidLoad NS_SWIFT_UI_ACTOR;
106106

107107
/**
108108
* @abstract Indicates that the receiver and all subnodes have finished displaying.
@@ -114,7 +114,7 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
114114
* the progressImage block.
115115
* @note This method is guaranteed to be called on main.
116116
*/
117-
- (void)hierarchyDisplayDidFinish;
117+
- (void)hierarchyDisplayDidFinish NS_SWIFT_UI_ACTOR;
118118

119119
@optional
120120
/**
@@ -125,7 +125,7 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
125125
* to attempt to ascend the node tree when handling this, as the root node is locked when this is
126126
* called.
127127
*/
128-
- (void)nodeWillCalculateLayout:(ASSizeRange)constrainedSize;
128+
- (void)nodeWillCalculateLayout:(ASSizeRange)constrainedSize NS_SWIFT_UI_ACTOR;
129129

130130
/**
131131
* @abstract Called when the node's layer is about to enter the hierarchy.
@@ -134,7 +134,7 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
134134
* re-parented multiple times, and each time will trigger this call.
135135
* @note This method is guaranteed to be called on main.
136136
*/
137-
- (void)didEnterHierarchy;
137+
- (void)didEnterHierarchy NS_SWIFT_UI_ACTOR;
138138

139139
/**
140140
* @abstract Called when the node's layer has exited the hierarchy.
@@ -143,6 +143,6 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
143143
* re-parented multiple times, and each time will trigger this call.
144144
* @note This method is guaranteed to be called on main.
145145
*/
146-
- (void)didExitHierarchy;
146+
- (void)didExitHierarchy NS_SWIFT_UI_ACTOR;
147147

148148
@end

Source/ASDisplayNode+Subclasses.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ NS_ASSUME_NONNULL_BEGIN
7171
* @discussion This is the best time to add gesture recognizers to the view.
7272
*/
7373
AS_CATEGORY_IMPLEMENTABLE
74-
- (void)didLoad ASDISPLAYNODE_REQUIRES_SUPER;
74+
- (void)didLoad ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
7575

7676
/**
7777
* An empty method that you can implement in a category to add global
@@ -95,7 +95,7 @@ AS_CATEGORY_IMPLEMENTABLE
9595
*
9696
* @discussion Subclasses override this method to layout all subnodes or subviews.
9797
*/
98-
- (void)layout ASDISPLAYNODE_REQUIRES_SUPER;
98+
- (void)layout ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
9999

100100
/**
101101
* @abstract Called on the main thread by the view's -layoutSubviews, after -layout.
@@ -104,7 +104,7 @@ AS_CATEGORY_IMPLEMENTABLE
104104
* out.
105105
*/
106106
AS_CATEGORY_IMPLEMENTABLE
107-
- (void)layoutDidFinish ASDISPLAYNODE_REQUIRES_SUPER;
107+
- (void)layoutDidFinish ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
108108

109109
/**
110110
* @abstract Called on a background thread if !isNodeLoaded - called on the main thread if isNodeLoaded.
@@ -255,7 +255,7 @@ AS_CATEGORY_IMPLEMENTABLE
255255
*
256256
* @note Called on the main thread only
257257
*/
258-
- (nullable id<NSObject>)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer;
258+
- (nullable id<NSObject>)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer NS_SWIFT_UI_ACTOR;
259259

260260
/**
261261
* @abstract Indicates that the receiver is about to display.
@@ -317,7 +317,7 @@ AS_CATEGORY_IMPLEMENTABLE
317317
* @discussion Called by -recursivelyClearContents. Always called on main thread. Base class implements self.contents = nil, clearing any backing
318318
* store, for asynchronous regeneration when needed.
319319
*/
320-
- (void)clearContents ASDISPLAYNODE_REQUIRES_SUPER;
320+
- (void)clearContents ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
321321

322322
/**
323323
* @abstract Indicates that the receiver is about to display its subnodes. This method is not called if there are no

0 commit comments

Comments
 (0)