Skip to content

Commit 5bafeca

Browse files
valeriyvanHeshamMegid
authored andcommitted
Parametrizes arrays which allows getting rid of annoying warning in swift code using HMSegmentedControl with images. (#268)
1 parent 0a3e665 commit 5bafeca

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

HMSegmentedControl/HMSegmentedControl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ typedef NS_ENUM(NSInteger, HMSegmentedControlType) {
5151

5252
@interface HMSegmentedControl : UIControl
5353

54-
@property (nonatomic, strong) NSArray *sectionTitles;
55-
@property (nonatomic, strong) NSArray *sectionImages;
56-
@property (nonatomic, strong) NSArray *sectionSelectedImages;
54+
@property (nonatomic, strong) NSArray<NSString *> *sectionTitles;
55+
@property (nonatomic, strong) NSArray<UIImage *> *sectionImages;
56+
@property (nonatomic, strong) NSArray<UIImage *> *sectionSelectedImages;
5757

5858
/**
5959
Provide a block to be executed when selected index is changed.
@@ -228,9 +228,9 @@ typedef NS_ENUM(NSInteger, HMSegmentedControlType) {
228228
*/
229229
@property (nonatomic) BOOL shouldAnimateUserSelection;
230230

231-
- (id)initWithSectionTitles:(NSArray *)sectiontitles;
232-
- (id)initWithSectionImages:(NSArray *)sectionImages sectionSelectedImages:(NSArray *)sectionSelectedImages;
233-
- (instancetype)initWithSectionImages:(NSArray *)sectionImages sectionSelectedImages:(NSArray *)sectionSelectedImages titlesForSections:(NSArray *)sectiontitles;
231+
- (id)initWithSectionTitles:(NSArray<NSString *> *)sectiontitles;
232+
- (id)initWithSectionImages:(NSArray<UIImage *> *)sectionImages sectionSelectedImages:(NSArray<UIImage *> *)sectionSelectedImages;
233+
- (instancetype)initWithSectionImages:(NSArray<UIImage *> *)sectionImages sectionSelectedImages:(NSArray<UIImage *> *)sectionSelectedImages titlesForSections:(NSArray<NSString *> *)sectiontitles;
234234
- (void)setSelectedSegmentIndex:(NSUInteger)index animated:(BOOL)animated;
235235
- (void)setIndexChangeBlock:(IndexChangeBlock)indexChangeBlock;
236236
- (void)setTitleFormatter:(HMTitleFormatterBlock)titleFormatter;

HMSegmentedControl/HMSegmentedControl.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ @interface HMSegmentedControl ()
1919
@property (nonatomic, strong) CALayer *selectionIndicatorBoxLayer;
2020
@property (nonatomic, strong) CALayer *selectionIndicatorArrowLayer;
2121
@property (nonatomic, readwrite) CGFloat segmentWidth;
22-
@property (nonatomic, readwrite) NSArray *segmentWidthsArray;
22+
@property (nonatomic, readwrite) NSArray<NSNumber *> *segmentWidthsArray;
2323
@property (nonatomic, strong) HMScrollView *scrollView;
2424

2525
@end
2626

2727
@implementation HMScrollView
2828

29-
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
29+
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
3030
if (!self.dragging) {
3131
[self.nextResponder touchesBegan:touches withEvent:event];
3232
} else {
3333
[super touchesBegan:touches withEvent:event];
3434
}
3535
}
3636

37-
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
37+
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
3838
if (!self.dragging) {
3939
[self.nextResponder touchesMoved:touches withEvent:event];
4040
} else{
4141
[super touchesMoved:touches withEvent:event];
4242
}
4343
}
4444

45-
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
45+
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
4646
if (!self.dragging) {
4747
[self.nextResponder touchesEnded:touches withEvent:event];
4848
} else {
@@ -72,7 +72,7 @@ - (id)initWithFrame:(CGRect)frame {
7272
return self;
7373
}
7474

75-
- (id)initWithSectionTitles:(NSArray *)sectiontitles {
75+
- (id)initWithSectionTitles:(NSArray<NSString *> *)sectiontitles {
7676
self = [super initWithFrame:CGRectZero];
7777

7878
if (self) {
@@ -84,7 +84,7 @@ - (id)initWithSectionTitles:(NSArray *)sectiontitles {
8484
return self;
8585
}
8686

87-
- (id)initWithSectionImages:(NSArray*)sectionImages sectionSelectedImages:(NSArray*)sectionSelectedImages {
87+
- (id)initWithSectionImages:(NSArray<UIImage *> *)sectionImages sectionSelectedImages:(NSArray<UIImage *> *)sectionSelectedImages {
8888
self = [super initWithFrame:CGRectZero];
8989

9090
if (self) {
@@ -97,14 +97,14 @@ - (id)initWithSectionImages:(NSArray*)sectionImages sectionSelectedImages:(NSArr
9797
return self;
9898
}
9999

100-
- (instancetype)initWithSectionImages:(NSArray *)sectionImages sectionSelectedImages:(NSArray *)sectionSelectedImages titlesForSections:(NSArray *)sectiontitles {
100+
- (instancetype)initWithSectionImages:(NSArray<UIImage *> *)sectionImages sectionSelectedImages:(NSArray<UIImage *> *)sectionSelectedImages titlesForSections:(NSArray<NSString *> *)sectiontitles {
101101
self = [super initWithFrame:CGRectZero];
102102

103103
if (self) {
104104
[self commonInit];
105105

106106
if (sectionImages.count != sectiontitles.count) {
107-
[NSException raise:NSRangeException format:@"***%s: Images bounds (%ld) Dont match Title bounds (%ld)", sel_getName(_cmd), (unsigned long)sectionImages.count, (unsigned long)sectiontitles.count];
107+
[NSException raise:NSRangeException format:@"***%s: Images bounds (%ld) Don't match Title bounds (%ld)", sel_getName(_cmd), (unsigned long)sectionImages.count, (unsigned long)sectiontitles.count];
108108
}
109109

110110
self.sectionImages = sectionImages;
@@ -174,14 +174,14 @@ - (void)setFrame:(CGRect)frame {
174174
[self updateSegmentsRects];
175175
}
176176

177-
- (void)setSectionTitles:(NSArray *)sectionTitles {
177+
- (void)setSectionTitles:(NSArray<NSString *> *)sectionTitles {
178178
_sectionTitles = sectionTitles;
179179

180180
[self setNeedsLayout];
181181
[self setNeedsDisplay];
182182
}
183183

184-
- (void)setSectionImages:(NSArray *)sectionImages {
184+
- (void)setSectionImages:(NSArray<UIImage *> *)sectionImages {
185185
_sectionImages = sectionImages;
186186

187187
[self setNeedsLayout];
@@ -695,7 +695,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {
695695

696696
#pragma mark - Touch
697697

698-
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
698+
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
699699
UITouch *touch = [touches anyObject];
700700
CGPoint touchLocation = [touch locationInView:self];
701701

HMSegmentedControlExample/ViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ - (void)viewDidLoad {
5454

5555

5656
// Segmented control with images
57-
NSArray *images = @[[UIImage imageNamed:@"1"],
57+
NSArray<UIImage *> *images = @[[UIImage imageNamed:@"1"],
5858
[UIImage imageNamed:@"2"],
5959
[UIImage imageNamed:@"3"],
6060
[UIImage imageNamed:@"4"]];
6161

62-
NSArray *selectedImages = @[[UIImage imageNamed:@"1-selected"],
62+
NSArray<UIImage *> *selectedImages = @[[UIImage imageNamed:@"1-selected"],
6363
[UIImage imageNamed:@"2-selected"],
6464
[UIImage imageNamed:@"3-selected"],
6565
[UIImage imageNamed:@"4-selected"]];

0 commit comments

Comments
 (0)