Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Modern Objective C: Fewer brackets
Browse files Browse the repository at this point in the history
Fewer brackets through property syntax.  Added stubs to remove
designated initialiser warnings on build and to better document the
interface.
  • Loading branch information
epreston committed Oct 27, 2015
1 parent 3d25340 commit 191b6a0
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 170 deletions.
2 changes: 1 addition & 1 deletion Example 1/Classes/Controller/PSHTreeGraphAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
14 changes: 7 additions & 7 deletions Example 1/Classes/Controller/PSHTreeGraphViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand All @@ -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"];
Expand Down Expand Up @@ -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];

}

Expand Down
6 changes: 3 additions & 3 deletions Example 1/Classes/Model/ObjCClass/ObjCClassWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (NSString *) name

- (NSString *) description
{
return [self name];
return self.name;
}

- (size_t) wrappedClassInstanceSize
Expand Down Expand Up @@ -138,12 +138,12 @@ - (NSArray *) subclasses

- (id <PSTreeGraphModelNode> ) parentModelNode
{
return [self superclassWrapper];
return self.superclassWrapper;
}

- (NSArray *) childModelNodes
{
return [self subclasses];
return self.subclasses;
}


Expand Down
36 changes: 18 additions & 18 deletions PSTreeGraphView/PSBaseBranchView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 )){
Expand All @@ -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 ) ||
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) ||
Expand Down Expand Up @@ -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];
Expand All @@ -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];
}

Expand Down
12 changes: 6 additions & 6 deletions PSTreeGraphView/PSBaseLeafView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions PSTreeGraphView/PSBaseSubtreeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 191b6a0

Please sign in to comment.