Improve designated initializer usage (#3132)

* Improve designated initializer usage

* Some more changes

* Add some whitespace

* Fix some warning
This commit is contained in:
Michael Schneider 2017-03-03 14:49:34 -08:00 committed by GitHub
parent 62d7e14ce1
commit eaa875c7f2
19 changed files with 76 additions and 26 deletions

View File

@ -191,9 +191,9 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
@interface ASCellNode (Unavailable) @interface ASCellNode (Unavailable)
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; - (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
- (void)setLayerBacked:(BOOL)layerBacked AS_UNAVAILABLE("ASCellNode does not support layer-backing"); - (void)setLayerBacked:(BOOL)layerBacked AS_UNAVAILABLE("ASCellNode does not support layer-backing");
@ -208,7 +208,7 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
/** /**
* Initializes a text cell with given text attributes and text insets * Initializes a text cell with given text attributes and text insets
*/ */
- (instancetype)initWithAttributes:(NSDictionary *)textAttributes insets:(UIEdgeInsets)textInsets; - (instancetype)initWithAttributes:(NSDictionary *)textAttributes insets:(UIEdgeInsets)textInsets NS_DESIGNATED_INITIALIZER;
/** /**
* Text to display. * Text to display.

View File

@ -125,7 +125,7 @@ extern NSInteger const ASDefaultDrawingPriority;
* @return An ASDisplayNode instance whose view will be a subclass that enables asynchronous rendering, and passes * @return An ASDisplayNode instance whose view will be a subclass that enables asynchronous rendering, and passes
* through -layout and touch handling methods. * through -layout and touch handling methods.
*/ */
- (instancetype)init; - (instancetype)init NS_DESIGNATED_INITIALIZER;
/** /**
@ -147,7 +147,7 @@ extern NSInteger const ASDefaultDrawingPriority;
* @return An ASDisplayNode instance that loads its view with the given block that is guaranteed to run on the main * @return An ASDisplayNode instance that loads its view with the given block that is guaranteed to run on the main
* queue. The view will render synchronously and -layout and touch handling methods on the node will not be called. * queue. The view will render synchronously and -layout and touch handling methods on the node will not be called.
*/ */
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock; - (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_DESIGNATED_INITIALIZER;
/** /**
* @abstract Alternative initializer with a block to create the backing layer. * @abstract Alternative initializer with a block to create the backing layer.
@ -168,7 +168,7 @@ extern NSInteger const ASDefaultDrawingPriority;
* @return An ASDisplayNode instance that loads its layer with the given block that is guaranteed to run on the main * @return An ASDisplayNode instance that loads its layer with the given block that is guaranteed to run on the main
* queue. The layer will render synchronously and -layout and touch handling methods on the node will not be called. * queue. The layer will render synchronously and -layout and touch handling methods on the node will not be called.
*/ */
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock; - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_DESIGNATED_INITIALIZER;
/** /**
* @abstract Add a block of work to be performed on the main thread when the node's view or layer is loaded. Thread safe. * @abstract Add a block of work to be performed on the main thread when the node's view or layer is loaded. Thread safe.

View File

@ -316,12 +316,11 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
- (instancetype)initWithViewClass:(Class)viewClass - (instancetype)initWithViewClass:(Class)viewClass
{ {
if (!(self = [super init])) if (!(self = [self init]))
return nil; return nil;
ASDisplayNodeAssert([viewClass isSubclassOfClass:[UIView class]], @"should initialize with a subclass of UIView"); ASDisplayNodeAssert([viewClass isSubclassOfClass:[UIView class]], @"should initialize with a subclass of UIView");
[self _initializeInstance];
_viewClass = viewClass; _viewClass = viewClass;
_flags.synchronous = ![viewClass isSubclassOfClass:[_ASDisplayView class]]; _flags.synchronous = ![viewClass isSubclassOfClass:[_ASDisplayView class]];
@ -330,12 +329,11 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
- (instancetype)initWithLayerClass:(Class)layerClass - (instancetype)initWithLayerClass:(Class)layerClass
{ {
if (!(self = [super init])) if (!(self = [self init]))
return nil; return nil;
ASDisplayNodeAssert([layerClass isSubclassOfClass:[CALayer class]], @"should initialize with a subclass of CALayer"); ASDisplayNodeAssert([layerClass isSubclassOfClass:[CALayer class]], @"should initialize with a subclass of CALayer");
[self _initializeInstance];
_layerClass = layerClass; _layerClass = layerClass;
_flags.synchronous = ![layerClass isSubclassOfClass:[_ASDisplayLayer class]]; _flags.synchronous = ![layerClass isSubclassOfClass:[_ASDisplayLayer class]];
_flags.layerBacked = YES; _flags.layerBacked = YES;

View File

@ -136,9 +136,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface ASEditableTextNode (Unavailable) @interface ASEditableTextNode (Unavailable)
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; - (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
@end @end

View File

@ -134,6 +134,16 @@ typedef NS_ENUM(NSUInteger, ASMultiplexImageNodeErrorCode) {
#endif #endif
@end @end
#pragma mark -
@interface ASMultiplexImageNode (Unavailable)
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
@end
#pragma mark - #pragma mark -
/** /**

View File

@ -149,7 +149,8 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
@implementation ASMultiplexImageNode @implementation ASMultiplexImageNode
#pragma mark - Getting Started / Tearing Down #pragma mark - Lifecycle
- (instancetype)initWithCache:(id<ASImageCacheProtocol>)cache downloader:(id<ASImageDownloaderProtocol>)downloader - (instancetype)initWithCache:(id<ASImageCacheProtocol>)cache downloader:(id<ASImageDownloaderProtocol>)downloader
{ {
if (!(self = [super init])) if (!(self = [super init]))
@ -179,6 +180,18 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
#endif #endif
} }
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock
{
ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER();
return [self init];
}
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock
{
ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER();
return [self init];
}
- (void)dealloc - (void)dealloc
{ {
[_phImageRequestOperation cancel]; [_phImageRequestOperation cancel];

View File

@ -112,6 +112,15 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
#pragma mark -
@interface ASNetworkImageNode (Unavailable)
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
@end
#pragma mark - #pragma mark -
/** /**

View File

@ -102,6 +102,18 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
#endif #endif
} }
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock
{
ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER();
return [self init];
}
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock
{
ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER();
return [self init];
}
- (void)dealloc - (void)dealloc
{ {
[self _cancelImageDownload]; [self _cancelImageDownload];

View File

@ -64,7 +64,7 @@
- (instancetype)init - (instancetype)init
{ {
return [super initWithViewBlock:^UIView *{ return [[ASScrollView alloc] init]; }]; return [super initWithViewBlock:^UIView *{ return [[ASScrollView alloc] init]; } didLoadBlock:nil];
} }
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize

View File

@ -282,9 +282,9 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) {
@interface ASTextNode (Unavailable) @interface ASTextNode (Unavailable)
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; - (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
@end @end

View File

@ -145,8 +145,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface ASVideoNode (Unavailable) @interface ASVideoNode (Unavailable)
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -29,9 +29,9 @@ ASDISPLAYNODE_EXTERN_C_END
@interface ASAbstractLayoutController (Unavailable) @interface ASAbstractLayoutController (Unavailable)
- (NSSet *)indexPathsForScrolling:(ASScrollDirection)scrollDirection rangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType __unavailable; - (NSSet *)indexPathsForScrolling:(ASScrollDirection)scrollDirection rangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType NS_UNAVAILABLE;
- (void)allIndexPathsForScrolling:(ASScrollDirection)scrollDirection rangeMode:(ASLayoutRangeMode)rangeMode displaySet:(NSSet * _Nullable * _Nullable)displaySet preloadSet:(NSSet * _Nullable * _Nullable)preloadSet __unavailable; - (void)allIndexPathsForScrolling:(ASScrollDirection)scrollDirection rangeMode:(ASLayoutRangeMode)rangeMode displaySet:(NSSet * _Nullable * _Nullable)displaySet preloadSet:(NSSet * _Nullable * _Nullable)preloadSet NS_UNAVAILABLE;
@end @end

View File

@ -144,7 +144,7 @@ ASDISPLAYNODE_EXTERN_C_END
@interface ASLayout (Unavailable) @interface ASLayout (Unavailable)
- (instancetype)init __unavailable; - (instancetype)init NS_UNAVAILABLE;
@end @end

View File

@ -14,7 +14,7 @@
#pragma mark - ASNullLayoutSpec #pragma mark - ASNullLayoutSpec
@interface ASNullLayoutSpec : ASLayoutSpec @interface ASNullLayoutSpec : ASLayoutSpec
- (instancetype)init __unavailable; - (instancetype)init NS_UNAVAILABLE;
+ (ASNullLayoutSpec *)null; + (ASNullLayoutSpec *)null;
@end @end

View File

@ -84,7 +84,7 @@ NS_ASSUME_NONNULL_BEGIN
/* /*
* Init not available for ASWrapperLayoutSpec * Init not available for ASWrapperLayoutSpec
*/ */
- (instancetype)init __unavailable; - (instancetype)init NS_UNAVAILABLE;
@end @end

View File

@ -24,6 +24,7 @@ AS_SUBCLASSING_RESTRICTED
@property (nonatomic, weak, readonly) UICollectionViewFlowLayout *layout; @property (nonatomic, weak, readonly) UICollectionViewFlowLayout *layout;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout NS_DESIGNATED_INITIALIZER; - (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout NS_DESIGNATED_INITIALIZER;
@end @end

View File

@ -93,7 +93,7 @@ AS_SUBCLASSING_RESTRICTED
@interface ASLayoutTransition (Unavailable) @interface ASLayoutTransition (Unavailable)
- (instancetype)init __unavailable; - (instancetype)init NS_UNAVAILABLE;
@end @end

View File

@ -21,8 +21,6 @@ NS_ASSUME_NONNULL_BEGIN
AS_SUBCLASSING_RESTRICTED AS_SUBCLASSING_RESTRICTED
@interface ASMutableElementMap : NSObject <NSCopying> @interface ASMutableElementMap : NSObject <NSCopying>
- (instancetype)init __unavailable;
- (instancetype)initWithSections:(NSArray<ASSection *> *)sections items:(ASCollectionElementTwoDimensionalArray *)items supplementaryElements:(ASSupplementaryElementDictionary *)supplementaryElements; - (instancetype)initWithSections:(NSArray<ASSection *> *)sections items:(ASCollectionElementTwoDimensionalArray *)items supplementaryElements:(ASSupplementaryElementDictionary *)supplementaryElements;
- (void)insertSection:(ASSection *)section atIndex:(NSInteger)index; - (void)insertSection:(ASSection *)section atIndex:(NSInteger)index;
@ -49,4 +47,10 @@ AS_SUBCLASSING_RESTRICTED
@interface ASElementMap (MutableCopying) <NSMutableCopying> @interface ASElementMap (MutableCopying) <NSMutableCopying>
@end @end
@interface ASMutableElementMap (Unavailable)
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -19,7 +19,7 @@
@property (nonatomic, assign, readonly) NSInteger sectionID; @property (nonatomic, assign, readonly) NSInteger sectionID;
@property (nonatomic, strong, nullable, readonly) id<ASSectionContext> context; @property (nonatomic, strong, nullable, readonly) id<ASSectionContext> context;
- (nullable instancetype)init __unavailable; - (nullable instancetype)init NS_UNAVAILABLE;
- (nullable instancetype)initWithSectionID:(NSInteger)sectionID context:(nullable id<ASSectionContext>)context NS_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithSectionID:(NSInteger)sectionID context:(nullable id<ASSectionContext>)context NS_DESIGNATED_INITIALIZER;
@end @end