Skip to content

Commit 2f5cc8d

Browse files
committed
Code modernization. Removed SWImageAdditions as it was broken.
1 parent 304b367 commit 2f5cc8d

16 files changed

+62
-133
lines changed

NSComboBox+SWBindingsAdditions.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
@implementation NSComboBox (SWBindingsAdditions)
1313

1414
- (id) selectedObjectInArray: (id)collection {
15-
int index = [self indexOfSelectedItem];
15+
int index = self.indexOfSelectedItem;
1616
NSLog (@"Index: %d", index);
1717

1818
NSArray *array = nil;
1919

2020
if (index == -1) {
2121
// We need to match by string value
22-
index = [self indexOfItemWithObjectValue:[self stringValue]];
22+
index = [self indexOfItemWithObjectValue:self.stringValue];
2323
}
2424

2525
// If index is still -1

NSDecimalNumber+RoundingExtensions.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ - (NSDecimalNumber *)decimalNumberByCeiling {
3131
}
3232

3333
- (NSDecimalNumber *)fractionalPart {
34-
return [self decimalNumberBySubtracting:[self decimalNumberByFlooring]];
34+
return [self decimalNumberBySubtracting:self.decimalNumberByFlooring];
3535
}
3636

3737
+ (NSDecimalNumber *) decimalNumberWithUnsignedInteger:(NSUInteger)integer {

NSFileManager+DirectoryLocations.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ - (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory i
6060
}
6161

6262
- (NSString *)applicationSupportDirectory {
63-
NSString *executableName = [[NSBundle mainBundle] infoDictionary][@"CFBundleExecutable"];
63+
NSString *executableName = [NSBundle mainBundle].infoDictionary[@"CFBundleExecutable"];
6464

6565
NSError *error = nil;
6666
NSString *result = [self findOrCreateDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask subdirectory:executableName error:&error];

NSImage+CenteredDrawing.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ @implementation NSImage (CenteredDrawing)
1515
- (void)drawCenteredInRect:(NSRect)inRect operation:(NSCompositingOperation)op fraction:(CGFloat)delta
1616
{
1717
NSRect srcRect = NSZeroRect;
18-
srcRect.size = [self size];
18+
srcRect.size = self.size;
1919

2020
// create a destination rect scaled to fit inside the frame
2121
NSRect drawnRect = srcRect;

NSMenuItem+SWShowHideAdditions.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (void) updateTitle:(NSString*)postfix isHidden: (BOOL)hidden {
3232

3333
title = [NSString stringWithFormat:@"%@ %@", prefix, postfix];
3434

35-
[self setTitle:title];
35+
self.title = title;
3636
}
3737

3838
@end

NSSet+SWSetAdditions.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ @implementation NSSet (SWSetAdditions)
1515

1616
- (NSSet*) subsetConformingTo: (SEL)selector {
1717
NSEnumerator *setEnumerator = [self objectEnumerator];
18-
NSMutableSet *newSet = [NSMutableSet setWithCapacity:[self count]];
18+
NSMutableSet *newSet = [NSMutableSet setWithCapacity:self.count];
1919
id object = nil;
2020

2121
while ((object = [setEnumerator nextObject])) {
@@ -28,7 +28,7 @@ - (NSSet*) subsetConformingTo: (SEL)selector {
2828

2929
- (NSSet*) subsetNotConformingTo: (SEL)selector {
3030
NSEnumerator *setEnumerator = [self objectEnumerator];
31-
NSMutableSet *newSet = [NSMutableSet setWithCapacity:[self count]];
31+
NSMutableSet *newSet = [NSMutableSet setWithCapacity:self.count];
3232
id object = nil;
3333

3434
while ((object = [setEnumerator nextObject])) {
@@ -41,7 +41,7 @@ - (NSSet*) subsetNotConformingTo: (SEL)selector {
4141

4242
- (NSSet*) subsetConformingTo: (SEL)selector withObject: (id)arg {
4343
NSEnumerator *setEnumerator = [self objectEnumerator];
44-
NSMutableSet *newSet = [NSMutableSet setWithCapacity:[self count]];
44+
NSMutableSet *newSet = [NSMutableSet setWithCapacity:self.count];
4545
id object = nil;
4646

4747
while ((object = [setEnumerator nextObject])) {
@@ -54,7 +54,7 @@ - (NSSet*) subsetConformingTo: (SEL)selector withObject: (id)arg {
5454

5555
- (NSSet*) subsetNotConformingTo: (SEL)selector withObject: (id)arg {
5656
NSEnumerator *setEnumerator = [self objectEnumerator];
57-
NSMutableSet *newSet = [NSMutableSet setWithCapacity:[self count]];
57+
NSMutableSet *newSet = [NSMutableSet setWithCapacity:self.count];
5858
id object = nil;
5959

6060
while ((object = [setEnumerator nextObject])) {

NSView+SetSubviewsEnabled.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ - (void) setSubviewsEnabled: (BOOL)enabled {
1919
}
2020

2121
- (void) recursivelySetEnabled: (BOOL)enabled {
22-
NSArray *subviews = [self subviews];
22+
NSArray *subviews = self.subviews;
2323
NSEnumerator *iter = [subviews objectEnumerator];
2424
id childView;
2525

SWControlValueAdditions.m

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,39 @@
1212
@implementation NSControl (SWControlNumberValue)
1313

1414
- (NSNumber*)numberValue {
15-
if ([self formatter])
16-
return [[self formatter] numberFromString:[self stringValue]];
15+
if (self.formatter)
16+
return [self.formatter numberFromString:self.stringValue];
1717
else
1818
return nil;
1919
}
2020

2121
- (NSDecimalNumber*)decimalNumberValue {
22-
if ([self formatter])
23-
return [NSDecimalNumber decimalNumberWithDecimal:[[self numberValue] decimalValue]];
22+
if (self.formatter)
23+
return [NSDecimalNumber decimalNumberWithDecimal:self.numberValue.decimalValue];
2424
else
25-
return [NSDecimalNumber decimalNumberWithString:[self stringValue]];
25+
return [NSDecimalNumber decimalNumberWithString:self.stringValue];
2626
}
2727

2828
- (void) setNumberValue: (NSNumber*)number {
29-
if ([self formatter])
30-
[self setStringValue:[[self formatter] stringFromNumber:number]];
29+
if (self.formatter)
30+
self.stringValue = [self.formatter stringFromNumber:number];
3131
else// if ([number isKindOfClass:[NSDecimalNumber class]])
32-
[self setStringValue:[(NSDecimalNumber*)number description]];
32+
self.stringValue = ((NSDecimalNumber*)number).description;
3333
}
3434

3535
@end
3636

3737
@implementation NSButton (SWControlBoolValue)
3838

3939
- (BOOL) boolValue {
40-
if ([self state] == NSOnState)
40+
if (self.state == NSOnState)
4141
return YES;
4242
else
4343
return NO;
4444
}
4545

4646
- (NSNumber*) boolNumberValue {
47-
return @([self boolValue]);
47+
return @(self.boolValue);
4848
}
4949

5050
@end

SWDocumentWindowController.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
@implementation NSWindowController (SWDocumentWindowController)
1313

1414
- (NSManagedObjectContext*) managedObjectContext {
15-
NSPersistentDocument *doc = [self document];
15+
NSPersistentDocument *doc = self.document;
1616

1717
if (doc)
18-
return [doc managedObjectContext];
18+
return doc.managedObjectContext;
1919

2020
return nil;
2121
}

SWGradientFillAdditions.m

+20-20
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,39 @@ + (CIVector*) vectorWithPoint: (NSPoint)point {
1919
}
2020

2121
- (float) lesserX: (CIVector*)other {
22-
if ([self X] < [other X])
23-
return [self X];
22+
if (self.X < other.X)
23+
return self.X;
2424
else
25-
return [other X];
25+
return other.X;
2626
}
2727

2828
- (float) lesserY: (CIVector*)other {
29-
if ([self Y] < [other Y])
30-
return [self Y];
29+
if (self.Y < other.Y)
30+
return self.Y;
3131
else
32-
return [other Y];
32+
return other.Y;
3333
}
3434

3535
- (float) lesserZ: (CIVector*)other {
36-
if ([self Z] < [other Z])
37-
return [self Z];
36+
if (self.Z < other.Z)
37+
return self.Z;
3838
else
39-
return [other Z];
39+
return other.Z;
4040
}
4141

4242
- (float) lesserW: (CIVector*)other {
43-
if ([self W] < [other W])
44-
return [self W];
43+
if (self.W < other.W)
44+
return self.W;
4545
else
46-
return [other W];
46+
return other.W;
4747
}
4848

4949
- (CIVector*) bottomLeft: (CIVector*)other {
5050
return [CIVector vectorWithX:[self lesserX:other] Y:[self lesserY:other] Z:[self lesserZ:other] W:[self lesserW:other]];
5151
}
5252

5353
- (CGPoint) toCGPoint {
54-
return CGPointMake([self X], [self Y]);
54+
return CGPointMake(self.X, self.Y);
5555
}
5656

5757
@end
@@ -64,8 +64,8 @@ - (void)fillGradientFrom: (CIVector*)startVector color:(NSColor*)inStartColor to
6464
inStartColor = [inStartColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
6565
inEndColor = [inEndColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
6666

67-
CIColor* startColor = [CIColor colorWithRed:[inStartColor redComponent] green:[inStartColor greenComponent] blue:[inStartColor blueComponent] alpha:[inStartColor alphaComponent]];
68-
CIColor* endColor = [CIColor colorWithRed:[inEndColor redComponent] green:[inEndColor greenComponent] blue:[inEndColor blueComponent] alpha:[inEndColor alphaComponent]];
67+
CIColor* startColor = [CIColor colorWithRed:inStartColor.redComponent green:inStartColor.greenComponent blue:inStartColor.blueComponent alpha:inStartColor.alphaComponent];
68+
CIColor* endColor = [CIColor colorWithRed:inEndColor.redComponent green:inEndColor.greenComponent blue:inEndColor.blueComponent alpha:inEndColor.alphaComponent];
6969

7070
CIVector *bottomLeft = [startVector bottomLeft:endVector];
7171

@@ -82,7 +82,7 @@ - (void)fillGradientFrom: (CIVector*)startVector color:(NSColor*)inStartColor to
8282

8383
[[NSGraphicsContext currentContext] saveGraphicsState];
8484

85-
CIContext* context = [[NSGraphicsContext currentContext] CIContext];
85+
CIContext* context = [NSGraphicsContext currentContext].CIContext;
8686

8787
//can be setClip, but this may increase the current clipping rect beyond that intended
8888
[self addClip];
@@ -93,7 +93,7 @@ - (void)fillGradientFrom: (CIVector*)startVector color:(NSColor*)inStartColor to
9393
};
9494

9595
CGRect gradientBounds = {
96-
[bottomLeft toCGPoint],
96+
bottomLeft.toCGPoint,
9797
self.bounds.size
9898
};
9999

@@ -103,7 +103,7 @@ - (void)fillGradientFrom: (CIVector*)startVector color:(NSColor*)inStartColor to
103103
}
104104

105105
- (void) fillVerticalGradientTop: (NSColor*)top bottom: (NSColor*)bottom {
106-
NSRect bounds = [self bounds];
106+
NSRect bounds = self.bounds;
107107

108108
NSPoint a = bounds.origin;
109109
NSPoint b = NSMakePoint(bounds.origin.x, bounds.origin.y + bounds.size.height);
@@ -112,7 +112,7 @@ - (void) fillVerticalGradientTop: (NSColor*)top bottom: (NSColor*)bottom {
112112
}
113113

114114
- (void) fillHorizontalGradientLeft: (NSColor*)left right: (NSColor*)right {
115-
NSRect bounds = [self bounds];
115+
NSRect bounds = self.bounds;
116116

117117
NSPoint a = bounds.origin;
118118
NSPoint b = NSMakePoint(bounds.origin.x + bounds.size.width, bounds.origin.y);
@@ -133,7 +133,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect
133133
}
134134

135135
- (void)drawRect:(NSRect)rect {
136-
NSRect viewBounds = [self bounds];
136+
NSRect viewBounds = self.bounds;
137137
NSBezierPath *p = [NSBezierPath bezierPathWithRect:viewBounds];
138138
NSColor *c = [[NSColor blueColor] colorWithAlphaComponent:0.1];
139139

SWImageAdditions.h

-20
This file was deleted.

SWImageAdditions.m

-51
This file was deleted.

SWIsNilDate.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (id)transformedValue:(id)value {
3434

3535
- (id)reverseTransformedValue:(id)value {
3636
//NSLog (@"Reverse Transforming: %@", value);
37-
if ([(NSNumber*)value boolValue])
37+
if (((NSNumber*)value).boolValue)
3838
return [NSDate date];
3939
else
4040
return nil;

0 commit comments

Comments
 (0)