Skip to content

Commit 9a173c1

Browse files
authored
Merge pull request #630 from TimOliver/clang-format
Run Clang Format on the project
2 parents e8c8ef0 + 4ee7faa commit 9a173c1

24 files changed

+1561
-1597
lines changed

.clang-format

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
# iOS Objective-C Style Guide
3+
# Based on Apple's coding conventions and common iOS practices
4+
5+
BasedOnStyle: LLVM
6+
7+
# Language specific settings
8+
Language: ObjC
9+
10+
# Indentation
11+
IndentWidth: 4
12+
TabWidth: 4
13+
UseTab: Never
14+
ContinuationIndentWidth: 4
15+
16+
# Line length
17+
ColumnLimit: 0
18+
19+
# Pointer and reference alignment
20+
PointerAlignment: Right
21+
ReferenceAlignment: Right
22+
23+
# Braces
24+
BreakBeforeBraces: Attach
25+
AllowShortBlocksOnASingleLine: Empty
26+
AllowShortFunctionsOnASingleLine: Empty
27+
AllowShortIfStatementsOnASingleLine: WithoutElse
28+
AllowShortLoopsOnASingleLine: false
29+
30+
# Method and function formatting
31+
AlignAfterOpenBracket: Align
32+
AllowAllParametersOfDeclarationOnNextLine: false
33+
BinPackParameters: false
34+
BinPackArguments: false
35+
36+
# Objective-C specific
37+
ObjCBinPackProtocolList: Never
38+
ObjCBlockIndentWidth: 4
39+
ObjCBreakBeforeNestedBlockParam: true
40+
ObjCSpaceAfterProperty: true
41+
ObjCSpaceBeforeProtocolList: true
42+
43+
# Spacing
44+
SpaceBeforeParens: ControlStatements
45+
SpaceBeforeAssignmentOperators: true
46+
SpaceAfterCStyleCast: false
47+
SpacesInContainerLiterals: false
48+
SpacesInParentheses: false
49+
SpacesInSquareBrackets: false
50+
51+
# Keep things together
52+
KeepEmptyLinesAtTheStartOfBlocks: false
53+
MaxEmptyLinesToKeep: 1
54+
55+
# Align consecutive assignments and declarations
56+
AlignConsecutiveAssignments: false
57+
AlignConsecutiveDeclarations: false
58+
59+
# Comments
60+
ReflowComments: true
61+
SpacesBeforeTrailingComments: 2
62+
63+
# Line breaks
64+
AllowShortCaseLabelsOnASingleLine: false
65+
AlwaysBreakAfterReturnType: None
66+
AlwaysBreakBeforeMultilineStrings: false
67+
BreakBeforeBinaryOperators: None
68+
BreakBeforeTernaryOperators: true
69+
70+
# Import/Include sorting
71+
SortIncludes: CaseInsensitive
72+
IncludeBlocks: Regroup
73+
IncludeCategories:
74+
- Regex: '^<.*\.h>'
75+
Priority: 1
76+
- Regex: '^<.*>'
77+
Priority: 2
78+
- Regex: '^"'
79+
Priority: 3
80+
81+
# Penalty weights (fine-tuning line breaks)
82+
PenaltyBreakBeforeFirstCallParameter: 19
83+
PenaltyBreakComment: 300
84+
PenaltyBreakFirstLessLess: 120
85+
PenaltyBreakString: 1000
86+
PenaltyExcessCharacter: 1000000
87+
PenaltyReturnTypeOnItsOwnLine: 200

Objective-C/TOCropViewController/Categories/UIImage+CropRotate.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424

2525
@implementation UIImage (CropRotate)
2626

27-
- (BOOL)hasAlpha
28-
{
27+
- (BOOL)hasAlpha {
2928
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(self.CGImage);
3029
return (alphaInfo == kCGImageAlphaFirst || alphaInfo == kCGImageAlphaLast ||
3130
alphaInfo == kCGImageAlphaPremultipliedFirst || alphaInfo == kCGImageAlphaPremultipliedLast);
3231
}
3332

34-
- (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular
35-
{
33+
- (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular {
3634
UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat new];
3735
format.opaque = !self.hasAlpha && !circular;
3836
format.scale = self.scale;
@@ -53,7 +51,7 @@ - (UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circular
5351
// If an angle was supplied, rotate the entire canvas + coordinate space to match
5452
if (angle != 0) {
5553
// Rotation in radians
56-
CGFloat rotation = angle * (M_PI/180.0f);
54+
CGFloat rotation = angle * (M_PI / 180.0f);
5755

5856
// Work out the new bounding size of the canvas after rotation
5957
CGRect imageBounds = (CGRect){CGPointZero, self.size};

Objective-C/TOCropViewController/Constants/TOCropViewConstants.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,36 @@
2626
The shape of the cropping region of this crop view controller
2727
*/
2828
typedef NS_ENUM(NSInteger, TOCropViewCroppingStyle) {
29-
TOCropViewCroppingStyleDefault, // The regular, rectangular crop box
30-
TOCropViewCroppingStyleCircular // A fixed, circular crop box
29+
TOCropViewCroppingStyleDefault, // The regular, rectangular crop box
30+
TOCropViewCroppingStyleCircular // A fixed, circular crop box
3131
};
3232

3333
/**
3434
Whether the control toolbar is placed at the bottom or the top
3535
*/
3636
typedef NS_ENUM(NSInteger, TOCropViewControllerToolbarPosition) {
3737
TOCropViewControllerToolbarPositionBottom, // Bar is placed along the bottom in portrait
38-
TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar)
38+
TOCropViewControllerToolbarPositionTop // Bar is placed along the top in portrait (Respects the status bar)
3939
};
4040

4141
static inline NSBundle *TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(NSObject *object) {
4242
#if SWIFT_PACKAGE
43-
// SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE
44-
// but I can't figure out how to make it work, so doing it manually
45-
NSString *bundleName = @"TOCropViewController_TOCropViewController";
43+
// SPM is supposed to support the keyword SWIFTPM_MODULE_BUNDLE
44+
// but I can't figure out how to make it work, so doing it manually
45+
NSString *bundleName = @"TOCropViewController_TOCropViewController";
4646
#else
47-
NSString *bundleName = @"TOCropViewControllerBundle";
47+
NSString *bundleName = @"TOCropViewControllerBundle";
4848
#endif
4949
NSBundle *resourceBundle = nil;
5050
NSBundle *classBundle = [NSBundle bundleForClass:object.class];
5151
NSURL *resourceBundleURL = [classBundle URLForResource:bundleName withExtension:@"bundle"];
5252
if (resourceBundleURL) {
5353
resourceBundle = [[NSBundle alloc] initWithURL:resourceBundleURL];
54-
#ifndef NDEBUG
55-
if (resourceBundle == nil) {
56-
@throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil];
57-
}
58-
#endif
54+
#ifndef NDEBUG
55+
if (resourceBundle == nil) {
56+
@throw [[NSException alloc] initWithName:@"BundleAccessor" reason:[NSString stringWithFormat:@"unable to find bundle named %@", bundleName] userInfo:nil];
57+
}
58+
#endif
5959
} else {
6060
resourceBundle = classBundle;
6161
}

Objective-C/TOCropViewController/Models/TOActivityCroppedImageProvider.m

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222

2323
#import "TOActivityCroppedImageProvider.h"
24+
2425
#import "UIImage+CropRotate.h"
2526

2627
@interface TOActivityCroppedImageProvider ()
@@ -36,38 +37,34 @@ @interface TOActivityCroppedImageProvider ()
3637

3738
@implementation TOActivityCroppedImageProvider
3839

39-
- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular
40-
{
40+
- (instancetype)initWithImage:(UIImage *)image cropFrame:(CGRect)cropFrame angle:(NSInteger)angle circular:(BOOL)circular {
4141
if (self = [super initWithPlaceholderItem:[UIImage new]]) {
4242
_image = image;
4343
_cropFrame = cropFrame;
4444
_angle = angle;
4545
_circular = circular;
4646
}
47-
47+
4848
return self;
4949
}
5050

5151
#pragma mark - UIActivity Protocols -
52-
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
53-
{
52+
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
5453
return [[UIImage alloc] init];
5554
}
5655

57-
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
58-
{
56+
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
5957
return self.croppedImage;
6058
}
6159

6260
#pragma mark - Image Generation -
63-
- (id)item
64-
{
65-
//If the user didn't touch the image, just forward along the original
61+
- (id)item {
62+
// If the user didn't touch the image, just forward along the original
6663
if (self.angle == 0 && CGRectEqualToRect(self.cropFrame, (CGRect){CGPointZero, self.image.size})) {
6764
self.croppedImage = self.image;
6865
return self.croppedImage;
6966
}
70-
67+
7168
UIImage *image = [self.image croppedImageWithFrame:self.cropFrame angle:self.angle circularClip:self.circular];
7269
self.croppedImage = image;
7370
return self.croppedImage;

Objective-C/TOCropViewController/Models/TOCropViewControllerAspectRatioPreset.m

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ @interface TOCropViewControllerAspectRatioPreset ()
3737

3838
@implementation TOCropViewControllerAspectRatioPreset
3939

40-
- (instancetype)initWithSize:(CGSize)size title:(NSString *)title
41-
{
40+
- (instancetype)initWithSize:(CGSize)size title:(NSString *)title {
4241
self = [super init];
4342
if (self) {
4443
_size = size;
@@ -58,37 +57,49 @@ - (BOOL)isEqual:(id)object {
5857
return CGSizeEqualToSize(self.size, other.size) && [self.title isEqualToString:other.title];
5958
}
6059

61-
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)portraitPresets
62-
{
60+
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)portraitPresets {
6361
TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"];
64-
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
62+
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
6563
return @[
66-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
67-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
68-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f) title:@"2:3"],
69-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f) title:@"3:5"],
70-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f) title:@"3:4"],
71-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f) title:@"4:5"],
72-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f) title:@"5:7"],
73-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f) title:@"9:16"],
64+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero
65+
title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
66+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f)
67+
title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
68+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(2.0f, 3.0f)
69+
title:@"2:3"],
70+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 5.0f)
71+
title:@"3:5"],
72+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 4.0f)
73+
title:@"3:4"],
74+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 5.0f)
75+
title:@"4:5"],
76+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 7.0f)
77+
title:@"5:7"],
78+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(9.0f, 16.0f)
79+
title:@"9:16"],
7480
];
7581
}
7682

77-
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)landscapePresets
78-
{
83+
+ (NSArray<TOCropViewControllerAspectRatioPreset *> *)landscapePresets {
7984
TOCropViewControllerAspectRatioPreset *object = [[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:@"Original"];
80-
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
85+
NSBundle *resourceBundle = TO_CROP_VIEW_RESOURCE_BUNDLE_FOR_OBJECT(object);
8186
return @[
82-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
83-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f) title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
84-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f) title:@"3:2"],
85-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f) title:@"5:3"],
86-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f) title:@"4:3"],
87-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f) title:@"5:4"],
88-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f) title:@"7:5"],
89-
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f) title:@"16:9"],
87+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeZero
88+
title:NSLocalizedStringFromTableInBundle(@"Original", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
89+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(1.0f, 1.0f)
90+
title:NSLocalizedStringFromTableInBundle(@"Square", @"TOCropViewControllerLocalizable", resourceBundle, nil)],
91+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(3.0f, 2.0f)
92+
title:@"3:2"],
93+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 3.0f)
94+
title:@"5:3"],
95+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(4.0f, 3.0f)
96+
title:@"4:3"],
97+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(5.0f, 4.0f)
98+
title:@"5:4"],
99+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(7.0f, 5.0f)
100+
title:@"7:5"],
101+
[[TOCropViewControllerAspectRatioPreset alloc] initWithSize:CGSizeMake(16.0f, 9.0f)
102+
title:@"16:9"],
90103
];
91104
}
92105
@end
93-
94-

Objective-C/TOCropViewController/Models/TOCropViewControllerTransitioning.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
2828
@interface TOCropViewControllerTransitioning : NSObject <UIViewControllerAnimatedTransitioning>
2929

3030
/* State Tracking */
31-
@property (nonatomic, assign) BOOL isDismissing; // Whether this animation is presenting or dismissing
32-
@property (nullable, nonatomic, strong) UIImage *image; // The image that will be used in this animation
31+
@property (nonatomic, assign) BOOL isDismissing; // Whether this animation is presenting or dismissing
32+
@property (nullable, nonatomic, strong) UIImage *image; // The image that will be used in this animation
3333

3434
/* Destination/Origin points */
3535
@property (nullable, nonatomic, strong) UIView *fromView; // The origin view who's frame the image will be animated from

0 commit comments

Comments
 (0)