I have 3 nested NSEnumeration
loops, which are used to get the textfields of a custom cell, in a custom table in a custom view in a controller.
How can I make this code more readable and more optimizated?
- (void) textfieldsOperations:(APOperation)op
{
__block int Valid = 0;
__block NSArray *sub = _Table.subviews;
__block MyCell *cell = nil;
__block UIView *view = nil;
__block NSMutableArray *ret = [NSMutableArray arrayWithCapacity:5];
[sub enumerateObjectsUsingBlock:^(id c, NSUInteger index, BOOL *stop)
{
if ( [c isKindOfClass:[MyCell class]] ) {
cell = c;
[cell.subviews enumerateObjectsUsingBlock:^(id v, NSUInteger index, BOOL *stop)
{
if ( [v isKindOfClass:[UIView class]] ) {
view = v;
[view.subviews enumerateObjectsUsingBlock:^(id t, NSUInteger index, BOOL *stop)
{
if ( [t isKindOfClass:[MyTextField class]] )
{
MyTextField *txt = t;
switch ( op )
{
case APOperationClear:
// something with "txt"
break;
case APOperationEnableSearch:
// something with "valid"
break;
case APOperationGetText:
// something with "txt"
break;
case APOperationPos: {
// something with "txt"
break;
}
}
}
}];
}
}];
}
}];
//[...]
}