Skip to content

Commit

Permalink
use Objective-C 2.0 subscripting for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dlo committed Oct 31, 2015
1 parent e54080f commit 65fdc6b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
12 changes: 6 additions & 6 deletions RETableViewManager/Cells/RETableViewInlinePickerCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ - (void)cellWillAppear
[super cellWillAppear];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.item.pickerItem.options enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([self.item.pickerItem.options objectAtIndex:idx] && [self.item.pickerItem.value objectAtIndex:idx] > 0)
[self.pickerView selectRow:[[self.item.pickerItem.options objectAtIndex:idx] indexOfObject:[self.item.pickerItem.value objectAtIndex:idx]] inComponent:idx animated:NO];
if (self.item.pickerItem.options[idx] && self.item.pickerItem.value[idx] > 0)
[self.pickerView selectRow:[self.item.pickerItem.options[idx] indexOfObject:self.item.pickerItem.value[idx]] inComponent:idx animated:NO];
}];
[self.pickerView reloadAllComponents];

Expand Down Expand Up @@ -106,16 +106,16 @@ - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [[self.item.pickerItem.options objectAtIndex:component] count];
return [self.item.pickerItem.options[component] count];
}

#pragma mark -
#pragma mark UIPickerViewDelegate

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSArray *items = [self.item.pickerItem.options objectAtIndex:component];
return [items objectAtIndex:row];
NSArray *items = self.item.pickerItem.options[component];
return items[row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
Expand All @@ -132,7 +132,7 @@ - (void)shouldUpdateItemValue
{
NSMutableArray *value = [NSMutableArray array];
[self.item.pickerItem.options enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSArray *options = [self.item.pickerItem.options objectAtIndex:idx];
NSArray *options = self.item.pickerItem.options[idx];
NSString *valueText = [options objectAtIndex:[self.pickerView selectedRowInComponent:idx]];
[value addObject:valueText];
}];
Expand Down
12 changes: 6 additions & 6 deletions RETableViewManager/Cells/RETableViewPickerCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated
if (selected && !self.item.inlinePicker) {
[self.textField becomeFirstResponder];
[self.item.options enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([self.item.options objectAtIndex:idx] && [self.item.value objectAtIndex:idx] > 0)
[self.pickerView selectRow:[[self.item.options objectAtIndex:idx] indexOfObject:[self.item.value objectAtIndex:idx]] inComponent:idx animated:NO];
if (self.item.options[idx] && self.item.value[idx] > 0)
[self.pickerView selectRow:[self.item.options[idx] indexOfObject:self.item.value[idx]] inComponent:idx animated:NO];
}];
}

Expand Down Expand Up @@ -164,7 +164,7 @@ - (void)shouldUpdateItemValue
{
NSMutableArray *value = [NSMutableArray array];
[self.item.options enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSArray *options = [self.item.options objectAtIndex:idx];
NSArray *options = self.item.options[idx];
NSString *valueText = [options objectAtIndex:[self.pickerView selectedRowInComponent:idx]];
[value addObject:valueText];
}];
Expand Down Expand Up @@ -245,16 +245,16 @@ - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [[self.item.options objectAtIndex:component] count];
return [self.item.options[component] count];
}

#pragma mark -
#pragma mark UIPickerViewDelegate

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSArray *items = [self.item.options objectAtIndex:component];
return [items objectAtIndex:row];
NSArray *items = self.item.options[component];
return items[row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
Expand Down
2 changes: 1 addition & 1 deletion RETableViewManager/Items/REMultipleChoiceItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (void)setValue:(NSArray *)value
self.detailLabelText = @"";

if (value.count == 1)
self.detailLabelText = [value objectAtIndex:0];
self.detailLabelText = value[0];

if (value.count > 1)
self.detailLabelText = [NSString stringWithFormat:NSLocalizedString(@"%i selected", @"%i selected"), value.count];
Expand Down
8 changes: 4 additions & 4 deletions RETableViewManager/RETableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ - (UIResponder *)responder

- (NSIndexPath *)indexPathForPreviousResponderInSectionIndex:(NSUInteger)sectionIndex
{
RETableViewSection *section = [self.tableViewManager.sections objectAtIndex:sectionIndex];
RETableViewSection *section = self.tableViewManager.sections[sectionIndex];
NSUInteger indexInSection = [section isEqual:self.section] ? [section.items indexOfObject:self.item] : section.items.count;
for (NSInteger i = indexInSection - 1; i >= 0; i--) {
RETableViewItem *item = [section.items objectAtIndex:i];
RETableViewItem *item = section.items[i];
if ([item isKindOfClass:[RETableViewItem class]]) {
Class class = [self.tableViewManager classForCellAtIndexPath:item.indexPath];
if ([class canFocusWithItem:item])
Expand All @@ -249,10 +249,10 @@ - (NSIndexPath *)indexPathForPreviousResponder

- (NSIndexPath *)indexPathForNextResponderInSectionIndex:(NSUInteger)sectionIndex
{
RETableViewSection *section = [self.tableViewManager.sections objectAtIndex:sectionIndex];
RETableViewSection *section = self.tableViewManager.sections[sectionIndex];
NSUInteger indexInSection = [section isEqual:self.section] ? [section.items indexOfObject:self.item] : -1;
for (NSInteger i = indexInSection + 1; i < section.items.count; i++) {
RETableViewItem *item = [section.items objectAtIndex:i];
RETableViewItem *item = section.items[i];
if ([item isKindOfClass:[RETableViewItem class]]) {
Class class = [self.tableViewManager classForCellAtIndexPath:item.indexPath];
if ([class canFocusWithItem:item])
Expand Down
80 changes: 40 additions & 40 deletions RETableViewManager/RETableViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ - (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key

- (Class)classForCellAtIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
NSObject *item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
NSObject *item = section.items[indexPath.row];
return [self.registeredClasses objectForKey:item.class];
}

Expand All @@ -172,13 +172,13 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
if (self.mutableSections.count <= sectionIndex) {
return 0;
}
return ((RETableViewSection *)[self.mutableSections objectAtIndex:sectionIndex]).items.count;
return ((RETableViewSection *)self.mutableSections[sectionIndex]).items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
RETableViewItem *item = section.items[indexPath.row];

UITableViewCellStyle cellStyle = UITableViewCellStyleDefault;
if ([item isKindOfClass:[RETableViewItem class]])
Expand Down Expand Up @@ -262,7 +262,7 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
if (self.mutableSections.count <= sectionIndex) {
return nil;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
RETableViewSection *section = self.mutableSections[sectionIndex];
return section.headerTitle;
}

Expand All @@ -271,17 +271,17 @@ - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInte
if (self.mutableSections.count <= sectionIndex) {
return nil;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
RETableViewSection *section = self.mutableSections[sectionIndex];
return section.footerTitle;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
RETableViewSection *sourceSection = [self.mutableSections objectAtIndex:sourceIndexPath.section];
RETableViewItem *item = [sourceSection.items objectAtIndex:sourceIndexPath.row];
RETableViewSection *sourceSection = self.mutableSections[sourceIndexPath.section];
RETableViewItem *item = sourceSection.items[sourceIndexPath.row];
[sourceSection removeItemAtIndex:sourceIndexPath.row];

RETableViewSection *destinationSection = [self.mutableSections objectAtIndex:destinationIndexPath.section];
RETableViewSection *destinationSection = self.mutableSections[destinationIndexPath.section];
[destinationSection insertItem:item atIndex:destinationIndexPath.row];

if (item.moveCompletionHandler)
Expand All @@ -293,17 +293,17 @@ - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)
if (self.mutableSections.count <= indexPath.section) {
return NO;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
RETableViewItem *item = section.items[indexPath.row];
return item.moveHandler != nil;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section < [self.mutableSections count]) {
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewSection *section = self.mutableSections[indexPath.section];
if (indexPath.row < [section.items count]) {
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
RETableViewItem *item = section.items[indexPath.row];
if ([item isKindOfClass:[RETableViewItem class]]) {
return item.editingStyle != UITableViewCellEditingStyleNone || item.moveHandler;
}
Expand All @@ -316,8 +316,8 @@ - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
RETableViewItem *item = section.items[indexPath.row];
if (item.deletionHandlerWithCompletion) {
item.deletionHandlerWithCompletion(item, ^{
[section removeItemAtIndex:indexPath.row];
Expand All @@ -344,8 +344,8 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
}

if (editingStyle == UITableViewCellEditingStyleInsert) {
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
RETableViewItem *item = section.items[indexPath.row];
if (item.insertionHandler)
item.insertionHandler(item);
}
Expand Down Expand Up @@ -411,8 +411,8 @@ - (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
id item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
id item = section.items[indexPath.row];

// Forward to UITableView delegate
//
Expand All @@ -427,7 +427,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
if (self.mutableSections.count <= sectionIndex) {
return UITableViewAutomaticDimension;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
RETableViewSection *section = self.mutableSections[sectionIndex];

if (section.headerHeight != RETableViewSectionHeaderHeightAutomatic) {
return section.headerHeight;
Expand Down Expand Up @@ -468,7 +468,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
if (self.mutableSections.count <= sectionIndex) {
return UITableViewAutomaticDimension;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
RETableViewSection *section = self.mutableSections[sectionIndex];

if (section.footerHeight != RETableViewSectionFooterHeightAutomatic) {
return section.footerHeight;
Expand Down Expand Up @@ -511,9 +511,9 @@ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(
if (self.mutableSections.count <= indexPath.section) {
return UITableViewAutomaticDimension;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewSection *section = self.mutableSections[indexPath.section];

id item = [section.items objectAtIndex:indexPath.row];
id item = section.items[indexPath.row];

// Forward to UITableView delegate
//
Expand All @@ -532,7 +532,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
if (self.mutableSections.count <= sectionIndex) {
return nil;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
RETableViewSection *section = self.mutableSections[sectionIndex];

// Forward to UITableView delegate
//
Expand All @@ -547,7 +547,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger
if (self.mutableSections.count <= sectionIndex) {
return nil;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
RETableViewSection *section = self.mutableSections[sectionIndex];

// Forward to UITableView delegate
//
Expand All @@ -561,8 +561,8 @@ - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
id item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
id item = section.items[indexPath.row];
if ([item respondsToSelector:@selector(setAccessoryButtonTapHandler:)]) {
RETableViewItem *actionItem = (RETableViewItem *)item;
if (actionItem.accessoryButtonTapHandler)
Expand Down Expand Up @@ -625,8 +625,8 @@ - (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
id item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
id item = section.items[indexPath.row];
if ([item respondsToSelector:@selector(setSelectionHandler:)]) {
RETableViewItem *actionItem = (RETableViewItem *)item;
if (actionItem.selectionHandler)
Expand All @@ -651,8 +651,8 @@ - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPat

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
RETableViewItem *item = section.items[indexPath.row];

if (![item isKindOfClass:[RETableViewItem class]])
return UITableViewCellEditingStyleNone;
Expand Down Expand Up @@ -705,8 +705,8 @@ - (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPa

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
RETableViewSection *sourceSection = [self.mutableSections objectAtIndex:sourceIndexPath.section];
RETableViewItem *item = [sourceSection.items objectAtIndex:sourceIndexPath.row];
RETableViewSection *sourceSection = self.mutableSections[sourceIndexPath.section];
RETableViewItem *item = sourceSection.items[sourceIndexPath.row];
if (item.moveHandler) {
BOOL allowed = item.moveHandler(item, sourceIndexPath, proposedDestinationIndexPath);
if (!allowed)
Expand Down Expand Up @@ -737,8 +737,8 @@ - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPat

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
id anItem = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
id anItem = section.items[indexPath.row];
if ([anItem respondsToSelector:@selector(setCopyHandler:)]) {
RETableViewItem *item = anItem;
if (item.copyHandler || item.pasteHandler)
Expand All @@ -755,8 +755,8 @@ - (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIn

- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
id anItem = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
id anItem = section.items[indexPath.row];
if ([anItem respondsToSelector:@selector(setCopyHandler:)]) {
RETableViewItem *item = anItem;
if (item.copyHandler && action == @selector(copy:))
Expand All @@ -779,8 +779,8 @@ - (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAt

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
RETableViewSection *section = self.mutableSections[indexPath.section];
RETableViewItem *item = section.items[indexPath.row];

if (action == @selector(copy:)) {
if (item.copyHandler)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 65fdc6b

Please sign in to comment.