Skip to content

Commit

Permalink
Fixes String Type Assertion. Closes dzenbot#60
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Romero Zurbuchen authored and Ignacio Romero committed Sep 21, 2015
1 parent 3a76cdf commit db11c70
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Source/DZNSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,17 @@ - (void)setItems:(NSArray *)items

_imageMode = [firstItem isKindOfClass:[UIImage class]];

NSPredicate *classPredicate = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", _imageMode ? [UIImage class] : [NSString class]];
Class class = _imageMode ? [UIImage class] : [NSString class];

// Consider cases where NSCFConstantString can also be used
class = [class isSubclassOfClass:[NSString class]] ? [NSString class] : class;

NSPredicate *classPredicate = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", class];
NSAssert([items filteredArrayUsingPredicate:classPredicate].count == items.count, @"Cannot include different objects in the array. Please make sure to either pass an array of NSString or UIImage objects.");

_items = [NSArray arrayWithArray:items];

if (!self.imageMode) {
if (!_imageMode) {
_counts = [NSMutableArray arrayWithCapacity:items.count];

for (int i = 0; i < items.count; i++) {
Expand Down

0 comments on commit db11c70

Please sign in to comment.