Permalink
Browse files

Modern Objective C: Fewer brackets

Fewer brackets through property syntax.  Added stubs to remove
designated initialiser warnings on build and to better document the
interface.
  • Loading branch information...
1 parent 3d25340 commit 191b6a0de9f11e4cf8dd0219de49011afd42b94c @epreston committed Oct 27, 2015
@@ -19,7 +19,7 @@ @implementation PSHTreeGraphAppDelegate
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
- [_window setRootViewController:_viewController];
+ _window.rootViewController = _viewController;
[_window addSubview:_viewController.view];
[_window makeKeyAndVisible];
@@ -35,7 +35,7 @@ - (void) setRootClassName:(NSString *)newRootClassName
// _treeGraphView.treeGraphOrientation = PSTreeGraphOrientationStyleHorizontalFlipped;
// Get an ObjCClassWrapper for the named Objective-C Class, and set it as the TreeGraph's root.
- [_treeGraphView setModelRoot:[ObjCClassWrapper wrapperForClassNamed:_rootClassName]];
+ _treeGraphView.modelRoot = [ObjCClassWrapper wrapperForClassNamed:_rootClassName];
}
}
@@ -48,14 +48,14 @@ - (void) viewDidLoad
[super viewDidLoad];
// Set the delegate to self.
- [self.treeGraphView setDelegate:self];
+ (self.treeGraphView).delegate = self;
// Specify a .nib file for the TreeGraph to load each time it needs to create a new node view.
- [self.treeGraphView setNodeViewNibName:@"ObjCClassTreeNodeView"];
+ (self.treeGraphView).nodeViewNibName = @"ObjCClassTreeNodeView";
// Specify a starting root class to inspect on launch.
- [self setRootClassName:@"UIControl"];
+ self.rootClassName = @"UIControl";
// The system includes some other abstract base classes that are interesting:
// [self setRootClassName:@"CAAnimation"];
@@ -89,14 +89,14 @@ -(void) configureNodeView:(UIView *)nodeView
MyLeafView *leafView = (MyLeafView *)nodeView;
// button
- if ( [[objectWrapper childModelNodes] count] == 0 ) {
+ if ( [objectWrapper childModelNodes].count == 0 ) {
[leafView.expandButton setHidden:YES];
}
// labels
- leafView.titleLabel.text = [objectWrapper name];
+ leafView.titleLabel.text = objectWrapper.name;
leafView.detailLabel.text = [NSString stringWithFormat:@"%zd bytes",
- [objectWrapper wrappedClassInstanceSize]];
+ objectWrapper.wrappedClassInstanceSize];
}
@@ -89,7 +89,7 @@ - (NSString *) name
- (NSString *) description
{
- return [self name];
+ return self.name;
}
- (size_t) wrappedClassInstanceSize
@@ -138,12 +138,12 @@ - (NSArray *) subclasses
- (id <PSTreeGraphModelNode> ) parentModelNode
{
- return [self superclassWrapper];
+ return self.superclassWrapper;
}
- (NSArray *) childModelNodes
{
- return [self subclasses];
+ return self.subclasses;
}
@@ -22,12 +22,12 @@ @implementation PSBaseBranchView
- (PSBaseTreeGraphView *) enclosingTreeGraph
{
- UIView *ancestor = [self superview];
+ UIView *ancestor = self.superview;
while (ancestor) {
if ([ancestor isKindOfClass:[PSBaseTreeGraphView class]]) {
return (PSBaseTreeGraphView *)ancestor;
}
- ancestor = [ancestor superview];
+ ancestor = ancestor.superview;
}
return nil;
}
@@ -37,10 +37,10 @@ - (PSBaseTreeGraphView *) enclosingTreeGraph
- (UIBezierPath *) directConnectionsPath
{
- CGRect bounds = [self bounds];
+ CGRect bounds = self.bounds;
CGPoint rootPoint = CGPointZero;
- PSTreeGraphOrientationStyle treeDirection = [[self enclosingTreeGraph] treeGraphOrientation];
+ PSTreeGraphOrientationStyle treeDirection = self.enclosingTreeGraph.treeGraphOrientation;
if (( treeDirection == PSTreeGraphOrientationStyleHorizontal ) ||
( treeDirection == PSTreeGraphOrientationStyleHorizontalFlipped )){
@@ -55,12 +55,12 @@ - (UIBezierPath *) directConnectionsPath
UIBezierPath *path = [UIBezierPath bezierPath];
// Add a stroke from rootPoint to each child SubtreeView of our containing SubtreeView.
- UIView *subtreeView = [self superview];
+ UIView *subtreeView = self.superview;
if ([subtreeView isKindOfClass:[PSBaseSubtreeView class]]) {
- for (UIView *subview in [subtreeView subviews]) {
+ for (UIView *subview in subtreeView.subviews) {
if ([subview isKindOfClass:[PSBaseSubtreeView class]]) {
- CGRect subviewBounds = [subview bounds];
+ CGRect subviewBounds = subview.bounds;
CGPoint targetPoint = CGPointZero;
if (( treeDirection == PSTreeGraphOrientationStyleHorizontal ) ||
@@ -100,10 +100,10 @@ - (UIBezierPath *) orthogonalConnectionsPath
// adjustment = adjustmentAsSize.width;
// }
- CGRect bounds = [self bounds];
+ CGRect bounds = self.bounds;
// CGPoint basePoint;
- PSTreeGraphOrientationStyle treeDirection = [[self enclosingTreeGraph] treeGraphOrientation];
+ PSTreeGraphOrientationStyle treeDirection = self.enclosingTreeGraph.treeGraphOrientation;
CGPoint rootPoint = CGPointZero;
if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) {
@@ -155,16 +155,16 @@ - (UIBezierPath *) orthogonalConnectionsPath
CGFloat minX = rootPoint.x;
CGFloat maxX = rootPoint.x;
- UIView *subtreeView = [self superview];
+ UIView *subtreeView = self.superview;
NSInteger subtreeViewCount = 0;
if ([subtreeView isKindOfClass:[PSBaseSubtreeView class]]) {
- for (UIView *subview in [subtreeView subviews]) {
+ for (UIView *subview in subtreeView.subviews) {
if ([subview isKindOfClass:[PSBaseSubtreeView class]]) {
++subtreeViewCount;
- CGRect subviewBounds = [subview bounds];
+ CGRect subviewBounds = subview.bounds;
CGPoint targetPoint = CGPointZero;
if (( treeDirection == PSTreeGraphOrientationStyleHorizontal ) ||
@@ -241,7 +241,7 @@ - (void) drawRect:(CGRect)dirtyRect
// Build the set of lines to stroke, according to our enclosingTreeGraph's connectingLineStyle.
UIBezierPath *path = nil;
- switch ([[self enclosingTreeGraph] connectingLineStyle]) {
+ switch (self.enclosingTreeGraph.connectingLineStyle) {
case PSTreeGraphConnectingLineStyleDirect:
default:
path = [self directConnectionsPath];
@@ -253,17 +253,17 @@ - (void) drawRect:(CGRect)dirtyRect
}
// Stroke the path with the appropriate color and line width.
- PSBaseTreeGraphView *treeGraph = [self enclosingTreeGraph];
+ PSBaseTreeGraphView *treeGraph = self.enclosingTreeGraph;
- if ( [self isOpaque] ) {
+ if ( self.opaque ) {
// Fill background.
- [[treeGraph backgroundColor] set];
+ [treeGraph.backgroundColor set];
UIRectFill(dirtyRect);
}
// Draw lines
- [[treeGraph connectingLineColor] set];
- [path setLineWidth:[treeGraph connectingLineWidth]];
+ [treeGraph.connectingLineColor set];
+ path.lineWidth = treeGraph.connectingLineWidth;
[path stroke];
}
@@ -93,19 +93,19 @@ - (void) updateLayerAppearanceToMatchContainerView
// CGFloat scaleFactor = [[self window] userSpaceScaleFactor];
CGFloat scaleFactor = 1.0f;
- CALayer *layer = [self layer];
+ CALayer *layer = self.layer;
- [layer setBorderWidth:(_borderWidth * scaleFactor)];
+ layer.borderWidth = (_borderWidth * scaleFactor);
if (_borderWidth > 0.0f) {
- [layer setBorderColor:[_borderColor CGColor]];
+ layer.borderColor = _borderColor.CGColor;
}
- [layer setCornerRadius:(_cornerRadius * scaleFactor)];
+ layer.cornerRadius = (_cornerRadius * scaleFactor);
if ( _showingSelected ) {
- [layer setBackgroundColor:[[self selectionColor] CGColor] ];
+ layer.backgroundColor = self.selectionColor.CGColor ;
} else {
- [layer setBackgroundColor:[[self fillColor] CGColor] ];
+ layer.backgroundColor = self.fillColor.CGColor ;
}
// // Disable implicit animations during these layer property changes
@@ -31,6 +31,11 @@
- (instancetype) initWithModelNode:( id <PSTreeGraphModelNode> )newModelNode NS_DESIGNATED_INITIALIZER;
+// Don't initialise with these:
+- (instancetype) initWithFrame:(CGRect)frame NS_UNAVAILABLE;
+- (instancetype) initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
+
+
/// The root of the model subtree that this SubtreeView represents.
@property (nonatomic, strong) id <PSTreeGraphModelNode> modelNode;
Oops, something went wrong.

0 comments on commit 191b6a0

Please sign in to comment.