Skip to content

Commit cac14e0

Browse files
authored
Standardize Property Declaration Style in Core Classes (#870)
* Audit property attributes for core classes * Update style guide * Go crazy * Update changelog
1 parent 9ccba7f commit cac14e0

164 files changed

Lines changed: 1100 additions & 1022 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
- Fix an issue where ASConfigurationDelegate would not call out for "control" users. If set, it now receives events whenever an experimental feature decision point occurs, whether it's enabled or not. [Adlai Holler](https://github.com/Adlai-Holler)
5656
- [ASDisplayNode] Fix an issue that causes a node to sometimes return an outdated calculated size or size range. [Huy Nguyen](https://github.com/nguyenhuy) [#808](https://github.com/TextureGroup/Texture/pull/808)
5757
- Add an experimental deallocation queue implementation that's more efficient. [Adlai Holler](https://github.com/Adlai-Holler)
58+
- Standardize property declaration style. [Adlai Holler](https://github.com/Adlai-Holler)
5859

5960
## 2.6
6061
- [Xcode 9] Updated to require Xcode 9 (to fix warnings) [Garrett Moon](https://github.com/garrettmoon)

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ static void someFunction() {
238238
- There is mostly no sense using nullability annotations outside of interface declarations.
239239
```objc
240240
// Properties
241-
@property(nonatomic, strong, nullable) NSNumber *status
241+
// Never include: `atomic`, `readwrite`, `strong`, `assign`.
242+
// Only specify nullability if it isn't assumed from NS_ASSUME.
243+
// (nullability, atomicity, storage class, writability, custom getter, custom setter)
244+
@property (nullable, copy) NSNumber *status
242245

243246
// Methods
244247
- (nullable NSNumber *)doSomethingWithString:(nullable NSString *)str;

Source/ASButtonNode.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,41 @@ typedef NS_ENUM(NSInteger, ASButtonNodeImageAlignment) {
3434

3535
@interface ASButtonNode : ASControlNode
3636

37-
@property (nonatomic, readonly) ASTextNode * titleNode;
38-
@property (nonatomic, readonly) ASImageNode * imageNode;
39-
@property (nonatomic, readonly) ASImageNode * backgroundImageNode;
37+
@property (readonly) ASTextNode * titleNode;
38+
@property (readonly) ASImageNode * imageNode;
39+
@property (readonly) ASImageNode * backgroundImageNode;
4040

4141
/**
4242
Spacing between image and title. Defaults to 8.0.
4343
*/
44-
@property (nonatomic, assign) CGFloat contentSpacing;
44+
@property CGFloat contentSpacing;
4545

4646
/**
4747
Whether button should be laid out vertically (image on top of text) or horizontally (image to the left of text).
4848
ASButton node does not yet support RTL but it should be fairly easy to implement.
4949
Defaults to YES.
5050
*/
51-
@property (nonatomic, assign) BOOL laysOutHorizontally;
51+
@property BOOL laysOutHorizontally;
5252

5353
/** Horizontally align content (text or image).
5454
Defaults to ASHorizontalAlignmentMiddle.
5555
*/
56-
@property (nonatomic, assign) ASHorizontalAlignment contentHorizontalAlignment;
56+
@property ASHorizontalAlignment contentHorizontalAlignment;
5757

5858
/** Vertically align content (text or image).
5959
Defaults to ASVerticalAlignmentCenter.
6060
*/
61-
@property (nonatomic, assign) ASVerticalAlignment contentVerticalAlignment;
61+
@property ASVerticalAlignment contentVerticalAlignment;
6262

6363
/**
6464
* @discussion The insets used around the title and image node
6565
*/
66-
@property (nonatomic, assign) UIEdgeInsets contentEdgeInsets;
66+
@property UIEdgeInsets contentEdgeInsets;
6767

6868
/**
6969
* @discusstion Whether the image should be aligned at the beginning or at the end of node. Default is `ASButtonNodeImageAlignmentBeginning`.
7070
*/
71-
@property (nonatomic, assign) ASButtonNodeImageAlignment imageAlignment;
71+
@property ASButtonNodeImageAlignment imageAlignment;
7272

7373
/**
7474
* Returns the styled title associated with the specified state.

Source/ASButtonNode.mm

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ - (instancetype)init
7878

7979
- (ASTextNode *)titleNode
8080
{
81+
ASLockScopeSelf();
8182
if (!_titleNode) {
8283
_titleNode = [[ASTextNode alloc] init];
8384
#if TARGET_OS_IOS
@@ -92,6 +93,7 @@ - (ASTextNode *)titleNode
9293

9394
- (ASImageNode *)imageNode
9495
{
96+
ASLockScopeSelf();
9597
if (!_imageNode) {
9698
_imageNode = [[ASImageNode alloc] init];
9799
[_imageNode setLayerBacked:YES];
@@ -101,6 +103,7 @@ - (ASImageNode *)imageNode
101103

102104
- (ASImageNode *)backgroundImageNode
103105
{
106+
ASLockScopeSelf();
104107
if (!_backgroundImageNode) {
105108
_backgroundImageNode = [[ASImageNode alloc] init];
106109
[_backgroundImageNode setLayerBacked:YES];
@@ -162,7 +165,7 @@ - (void)setDisplaysAsynchronously:(BOOL)displaysAsynchronously
162165
- (void)updateImage
163166
{
164167
[self lock];
165-
168+
166169
UIImage *newImage;
167170
if (self.enabled == NO && _disabledImage) {
168171
newImage = _disabledImage;
@@ -253,16 +256,9 @@ - (CGFloat)contentSpacing
253256

254257
- (void)setContentSpacing:(CGFloat)contentSpacing
255258
{
256-
{
257-
ASLockScopeSelf();
258-
if (contentSpacing == _contentSpacing) {
259-
return;
260-
}
261-
262-
_contentSpacing = contentSpacing;
259+
if (ASLockedSelfCompareAssign(_contentSpacing, contentSpacing)) {
260+
[self setNeedsLayout];
263261
}
264-
265-
[self setNeedsLayout];
266262
}
267263

268264
- (BOOL)laysOutHorizontally
@@ -273,16 +269,9 @@ - (BOOL)laysOutHorizontally
273269

274270
- (void)setLaysOutHorizontally:(BOOL)laysOutHorizontally
275271
{
276-
{
277-
ASLockScopeSelf();
278-
if (laysOutHorizontally == _laysOutHorizontally) {
279-
return;
280-
}
281-
282-
_laysOutHorizontally = laysOutHorizontally;
272+
if (ASLockedSelfCompareAssign(_laysOutHorizontally, laysOutHorizontally)) {
273+
[self setNeedsLayout];
283274
}
284-
285-
[self setNeedsLayout];
286275
}
287276

288277
- (ASVerticalAlignment)contentVerticalAlignment

Source/ASCellNode.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
8080
* blocking time is very short. If the rangeTuningParameters are set to 0, still this option
8181
* outperforms UIKit: while the main thread is waiting, subnode display executes concurrently.
8282
*/
83-
@property (nonatomic, assign) BOOL neverShowPlaceholders;
83+
@property BOOL neverShowPlaceholders;
8484

8585
/*
8686
* The kind of supplementary element this node represents, if any.
8787
*
8888
* @return The supplementary element kind, or @c nil if this node does not represent a supplementary element.
8989
*/
90-
@property (atomic, copy, readonly, nullable) NSString *supplementaryElementKind;
90+
@property (nullable, copy, readonly) NSString *supplementaryElementKind;
9191

9292
/*
9393
* The layout attributes currently assigned to this node, if any.
@@ -96,25 +96,25 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
9696
* is called, when the node is not yet in the hierarchy and its frame cannot be converted to/from other nodes. Instead
9797
* you can use the layout attributes object to learn where and how the cell will be displayed.
9898
*/
99-
@property (nonatomic, strong, readonly, nullable) UICollectionViewLayoutAttributes *layoutAttributes;
99+
@property (nullable, copy, readonly) UICollectionViewLayoutAttributes *layoutAttributes;
100100

101101
/**
102102
* A Boolean value that is synchronized with the underlying collection or tableView cell property.
103103
* Setting this value is equivalent to calling selectItem / deselectItem on the collection or table.
104104
*/
105-
@property (nonatomic, assign, getter=isSelected) BOOL selected;
105+
@property (getter=isSelected) BOOL selected;
106106

107107
/**
108108
* A Boolean value that is synchronized with the underlying collection or tableView cell property.
109109
* Setting this value is equivalent to calling highlightItem / unHighlightItem on the collection or table.
110110
*/
111-
@property (nonatomic, assign, getter=isHighlighted) BOOL highlighted;
111+
@property (getter=isHighlighted) BOOL highlighted;
112112

113113
/**
114114
* The current index path of this cell node, or @c nil if this node is
115115
* not a valid item inside a table node or collection node.
116116
*/
117-
@property (atomic, readonly, nullable) NSIndexPath *indexPath;
117+
@property (nullable, copy, readonly) NSIndexPath *indexPath;
118118

119119
/**
120120
* BETA: API is under development. We will attempt to provide an easy migration pathway for any changes.
@@ -123,7 +123,7 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
123123
*
124124
* This property may be set off the main thread, but this method will never be invoked concurrently on the
125125
*/
126-
@property (atomic, nullable) id nodeModel;
126+
@property (nullable) id nodeModel;
127127

128128
/**
129129
* Asks the node whether it can be updated to the given node model.
@@ -136,13 +136,13 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
136136
* The backing view controller, or @c nil if the node wasn't initialized with backing view controller
137137
* @note This property must be accessed on the main thread.
138138
*/
139-
@property (nonatomic, readonly, nullable) UIViewController *viewController;
139+
@property (nullable, nonatomic, readonly) UIViewController *viewController;
140140

141141

142142
/**
143143
* The table- or collection-node that this cell is a member of, if any.
144144
*/
145-
@property (atomic, weak, readonly, nullable) id<ASRangeManagingNode> owningNode;
145+
@property (nullable, weak, readonly) id<ASRangeManagingNode> owningNode;
146146

147147
/*
148148
* ASCellNode must forward touch events in order for UITableView and UICollectionView tap handling to work. Overriding
@@ -188,38 +188,38 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
188188
* @default UITableViewCellSelectionStyleDefault
189189
* ASTableView uses these properties when configuring UITableViewCells that host ASCellNodes.
190190
*/
191-
@property (nonatomic) UITableViewCellSelectionStyle selectionStyle;
191+
@property UITableViewCellSelectionStyle selectionStyle;
192192

193193
/* @abstract The focus style when a cell is focused
194194
* @default UITableViewCellFocusStyleDefault
195195
* ASTableView uses these properties when configuring UITableViewCells that host ASCellNodes.
196196
*/
197-
@property (nonatomic) UITableViewCellFocusStyle focusStyle;
197+
@property UITableViewCellFocusStyle focusStyle;
198198

199199
/* @abstract The view used as the background of the cell when it is selected.
200200
* ASTableView uses these properties when configuring UITableViewCells that host ASCellNodes.
201201
* ASCollectionView uses these properties when configuring UICollectionViewCells that host ASCellNodes.
202202
*/
203-
@property (nonatomic, strong, nullable) UIView *selectedBackgroundView;
203+
@property (nullable) UIView *selectedBackgroundView;
204204

205205
/* @abstract The accessory type view on the right side of the cell. Please take care of your ASLayoutSpec so that doesn't overlay the accessoryView
206206
* @default UITableViewCellAccessoryNone
207207
* ASTableView uses these properties when configuring UITableViewCells that host ASCellNodes.
208208
*/
209-
@property (nonatomic) UITableViewCellAccessoryType accessoryType;
209+
@property UITableViewCellAccessoryType accessoryType;
210210

211211
/* @abstract The inset of the cell separator line
212212
* ASTableView uses these properties when configuring UITableViewCells that host ASCellNodes.
213213
*/
214-
@property (nonatomic) UIEdgeInsets separatorInset;
214+
@property UIEdgeInsets separatorInset;
215215

216216
@end
217217

218218
@interface ASCellNode (Unavailable)
219219

220-
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable;
220+
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
221221

222-
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable;
222+
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;
223223

224224
- (void)setLayerBacked:(BOOL)layerBacked AS_UNAVAILABLE("ASCellNode does not support layer-backing, although subnodes may be layer-backed.");
225225

@@ -239,22 +239,22 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
239239
/**
240240
* Text to display.
241241
*/
242-
@property (nonatomic, copy) NSString *text;
242+
@property (nullable, copy) NSString *text;
243243

244244
/**
245245
* A dictionary containing key-value pairs for text attributes. You can specify the font, text color, text shadow color, and text shadow offset using the keys listed in NSString UIKit Additions Reference.
246246
*/
247-
@property (nonatomic, copy) NSDictionary *textAttributes;
247+
@property (copy) NSDictionary<NSAttributedStringKey, id> *textAttributes;
248248

249249
/**
250250
* The text inset or outset for each edge. The default value is 15.0 horizontal and 11.0 vertical padding.
251251
*/
252-
@property (nonatomic, assign) UIEdgeInsets textInsets;
252+
@property UIEdgeInsets textInsets;
253253

254254
/**
255255
* The text node used by this cell node.
256256
*/
257-
@property (nonatomic, strong, readonly) ASTextNode *textNode;
257+
@property (readonly) ASTextNode *textNode;
258258

259259
@end
260260

0 commit comments

Comments
 (0)