Skip to content

Improve nullable annotations for _ASDisplayLayer and _ASDisplayView #trivial #780

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

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Source/Details/_ASDisplayLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#import <AsyncDisplayKit/ASBaseDefines.h>
#import <AsyncDisplayKit/ASBlockTypes.h>

NS_ASSUME_NONNULL_BEGIN

@class ASDisplayNode;
@protocol _ASDisplayLayerDelegate;

Expand All @@ -28,7 +30,7 @@
@discussion This property overrides the CALayer category method which implements this via associated objects.
This should result in much better performance for _ASDisplayLayers.
*/
@property (nonatomic, weak) ASDisplayNode *asyncdisplaykit_node;
@property (nullable, nonatomic, weak) ASDisplayNode *asyncdisplaykit_node;
Copy link
Member

Choose a reason for hiding this comment

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

Weak properties are nullable by default.

Copy link
Contributor Author

@maicki maicki Jan 31, 2018

Choose a reason for hiding this comment

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

I would rather go with the explicit case. You are right in theory the compiler is creating the exact same output, but if you look into Apple's header, e.g. UITableView.h weak properties like delegate or dataSource are still annotated with nullable.

Copy link
Member

Choose a reason for hiding this comment

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

👌


/**
@summary Set to YES to enable asynchronous display for the receiver.
Expand Down Expand Up @@ -57,7 +59,7 @@

@desc The asyncDelegate will have the opportunity to override the methods related to async display.
*/
@property (atomic, weak) id<_ASDisplayLayerDelegate> asyncDelegate;
@property (nullable, atomic, weak) id<_ASDisplayLayerDelegate> asyncDelegate;

/**
@summary Suspends both asynchronous and synchronous display of the receiver if YES.
Expand Down Expand Up @@ -109,15 +111,19 @@
@param isCancelledBlock Execute this block to check whether the current drawing operation has been cancelled to avoid unnecessary work. A return value of YES means cancel drawing and return.
@param isRasterizing YES if the layer is being rasterized into another layer, in which case drawRect: probably wants to avoid doing things like filling its bounds with a zero-alpha color to clear the backing store.
*/
+ (void)drawRect:(CGRect)bounds withParameters:(id)parameters isCancelled:(AS_NOESCAPE asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing;
+ (void)drawRect:(CGRect)bounds
withParameters:(nullable id)parameters
isCancelled:(AS_NOESCAPE asdisplaynode_iscancelled_block_t)isCancelledBlock
isRasterizing:(BOOL)isRasterizing;

/**
@summary Delegate override to provide new layer contents as a UIImage.
@param parameters An object describing all of the properties you need to draw. Return this from -drawParametersForAsyncLayer:
@param isCancelledBlock Execute this block to check whether the current drawing operation has been cancelled to avoid unnecessary work. A return value of YES means cancel drawing and return.
@return A UIImage with contents that are ready to display on the main thread. Make sure that the image is already decoded before returning it here.
*/
+ (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(AS_NOESCAPE asdisplaynode_iscancelled_block_t)isCancelledBlock;
+ (UIImage *)displayWithParameters:(nullable id<NSObject>)parameters
isCancelled:(AS_NOESCAPE asdisplaynode_iscancelled_block_t)isCancelledBlock;

// Called on the main thread only

Expand Down Expand Up @@ -147,3 +153,5 @@
- (void)cancelDisplayAsyncLayer:(_ASDisplayLayer *)asyncLayer;

@end

NS_ASSUME_NONNULL_END
6 changes: 5 additions & 1 deletion Source/Details/_ASDisplayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

// This class is only for use by ASDisplayNode and should never be subclassed or used directly.
// Note that the "node" property is added to UIView directly via a category in ASDisplayNode.

Expand All @@ -28,7 +30,7 @@
@discussion This property overrides the UIView category method which implements this via associated objects.
This should result in much better performance for _ASDisplayView.
*/
@property (nonatomic, weak) ASDisplayNode *asyncdisplaykit_node;
@property (nullable, nonatomic, weak) ASDisplayNode *asyncdisplaykit_node;

// These methods expose a way for ASDisplayNode touch events to let the view call super touch events
// Some UIKit mechanisms, like UITableView and UICollectionView selection handling, require this to work
Expand All @@ -38,3 +40,5 @@
- (void)__forwardTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

@end

NS_ASSUME_NONNULL_END