Skip to content

Commit

Permalink
Improve designated initializer usage (#3132)
Browse files Browse the repository at this point in the history
* Improve designated initializer usage

* Some more changes

* Add some whitespace

* Fix some warning
  • Loading branch information
maicki authored Mar 3, 2017
1 parent 62d7e14 commit eaa875c
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Source/ASCellNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {

@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");

Expand All @@ -208,7 +208,7 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
/**
* 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.
Expand Down
6 changes: 3 additions & 3 deletions Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extern NSInteger const ASDefaultDrawingPriority;
* @return An ASDisplayNode instance whose view will be a subclass that enables asynchronous rendering, and passes
* through -layout and touch handling methods.
*/
- (instancetype)init;
- (instancetype)init NS_DESIGNATED_INITIALIZER;


/**
Expand All @@ -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
* 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.
Expand All @@ -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
* 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.
Expand Down
6 changes: 2 additions & 4 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ - (instancetype)init

- (instancetype)initWithViewClass:(Class)viewClass
{
if (!(self = [super init]))
if (!(self = [self init]))
return nil;

ASDisplayNodeAssert([viewClass isSubclassOfClass:[UIView class]], @"should initialize with a subclass of UIView");

[self _initializeInstance];
_viewClass = viewClass;
_flags.synchronous = ![viewClass isSubclassOfClass:[_ASDisplayView class]];

Expand All @@ -330,12 +329,11 @@ - (instancetype)initWithViewClass:(Class)viewClass

- (instancetype)initWithLayerClass:(Class)layerClass
{
if (!(self = [super init]))
if (!(self = [self init]))
return nil;

ASDisplayNodeAssert([layerClass isSubclassOfClass:[CALayer class]], @"should initialize with a subclass of CALayer");

[self _initializeInstance];
_layerClass = layerClass;
_flags.synchronous = ![layerClass isSubclassOfClass:[_ASDisplayLayer class]];
_flags.layerBacked = YES;
Expand Down
4 changes: 2 additions & 2 deletions Source/ASEditableTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ NS_ASSUME_NONNULL_BEGIN

@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

Expand Down
10 changes: 10 additions & 0 deletions Source/ASMultiplexImageNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ typedef NS_ENUM(NSUInteger, ASMultiplexImageNodeErrorCode) {
#endif
@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 -
/**
Expand Down
15 changes: 14 additions & 1 deletion Source/ASMultiplexImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ - (void)_downloadImageWithIdentifier:(id)imageIdentifier URL:(NSURL *)imageURL c

@implementation ASMultiplexImageNode

#pragma mark - Getting Started / Tearing Down
#pragma mark - Lifecycle

- (instancetype)initWithCache:(id<ASImageCacheProtocol>)cache downloader:(id<ASImageDownloaderProtocol>)downloader
{
if (!(self = [super init]))
Expand Down Expand Up @@ -179,6 +180,18 @@ - (instancetype)init
#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
{
[_phImageRequestOperation cancel];
Expand Down
9 changes: 9 additions & 0 deletions Source/ASNetworkImageNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ NS_ASSUME_NONNULL_BEGIN

@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 -
/**
Expand Down
12 changes: 12 additions & 0 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ - (instancetype)init
#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
{
[self _cancelImageDownload];
Expand Down
2 changes: 1 addition & 1 deletion Source/ASScrollNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ @implementation ASScrollNode

- (instancetype)init
{
return [super initWithViewBlock:^UIView *{ return [[ASScrollView alloc] init]; }];
return [super initWithViewBlock:^UIView *{ return [[ASScrollView alloc] init]; } didLoadBlock:nil];
}

- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
Expand Down
4 changes: 2 additions & 2 deletions Source/ASTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) {

@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

Expand Down
5 changes: 4 additions & 1 deletion Source/ASVideoNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ NS_ASSUME_NONNULL_BEGIN

@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


NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions Source/Details/ASAbstractLayoutController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ ASDISPLAYNODE_EXTERN_C_END

@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

Expand Down
2 changes: 1 addition & 1 deletion Source/Layout/ASLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ASDISPLAYNODE_EXTERN_C_END

@interface ASLayout (Unavailable)

- (instancetype)init __unavailable;
- (instancetype)init NS_UNAVAILABLE;

@end

Expand Down
2 changes: 1 addition & 1 deletion Source/Layout/ASLayoutSpec+Subclasses.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#pragma mark - ASNullLayoutSpec

@interface ASNullLayoutSpec : ASLayoutSpec
- (instancetype)init __unavailable;
- (instancetype)init NS_UNAVAILABLE;
+ (ASNullLayoutSpec *)null;
@end

Expand Down
2 changes: 1 addition & 1 deletion Source/Layout/ASLayoutSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ NS_ASSUME_NONNULL_BEGIN
/*
* Init not available for ASWrapperLayoutSpec
*/
- (instancetype)init __unavailable;
- (instancetype)init NS_UNAVAILABLE;

@end

Expand Down
1 change: 1 addition & 0 deletions Source/Private/ASCollectionViewFlowLayoutInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AS_SUBCLASSING_RESTRICTED
@property (nonatomic, weak, readonly) UICollectionViewFlowLayout *layout;

- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithFlowLayout:(UICollectionViewFlowLayout *)flowLayout NS_DESIGNATED_INITIALIZER;

@end
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/ASLayoutTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ AS_SUBCLASSING_RESTRICTED

@interface ASLayoutTransition (Unavailable)

- (instancetype)init __unavailable;
- (instancetype)init NS_UNAVAILABLE;

@end

Expand Down
8 changes: 6 additions & 2 deletions Source/Private/ASMutableElementMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ NS_ASSUME_NONNULL_BEGIN
AS_SUBCLASSING_RESTRICTED
@interface ASMutableElementMap : NSObject <NSCopying>

- (instancetype)init __unavailable;

- (instancetype)initWithSections:(NSArray<ASSection *> *)sections items:(ASCollectionElementTwoDimensionalArray *)items supplementaryElements:(ASSupplementaryElementDictionary *)supplementaryElements;

- (void)insertSection:(ASSection *)section atIndex:(NSInteger)index;
Expand All @@ -49,4 +47,10 @@ AS_SUBCLASSING_RESTRICTED
@interface ASElementMap (MutableCopying) <NSMutableCopying>
@end

@interface ASMutableElementMap (Unavailable)

- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion Source/Private/ASSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@property (nonatomic, assign, readonly) NSInteger sectionID;
@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;

@end

0 comments on commit eaa875c

Please sign in to comment.