开发者

Dead code with Xcode anaylser

开发者 https://www.devze.com 2023-03-25 08:41 出处:网络
i wanted to analyse my projet, and xcode analyser find some Dead Code in my rootcontroller Xcode tell me that :

i wanted to analyse my projet, and xcode analyser find some Dead Code in my rootcontroller Xcode tell me that :

Dead code
The left operand to '+' is always 0
-> Variable 'i' initialized to 0
-> The left operand to '+' is always 0

Can someone explain me this ans how to clean that code, thanks....

here is my rootcontroller.m

#import "RootViewController22.h"
#import "LabelCell.h"
#import "NibLoadedCell.h"
#import "GradientBackgroundTable.h"
#import "NibLoadedCell2.h"
#import "NibLoadedCell3.h"

@implementation RootViewController22

//
// title
//
// returns the navigation bar text for the front screen
//


/*- (NSString *)title
{
    return NSLocalizedString(@"Les Robes du Bengal", @"");
}*/



//
// createRows
//
// Constructs all the rows on the front screen and animates them in
//
- (void)createRows
{


    [self addSectionAtIndex:0 withAnimation:UITableViewRowAnimationFade];
    for (NSInteger i = 0; i < 1; i++)
    {
        [self
         appendRowToSection:0
         cellClass:[NibLoadedCell2 class]
         cellData:[NSString stringWithFormat:
                   NSLocalizedString(@"This is row %ld", @""), i + 1]
         withAnimation:(i % 2) == 0 ?
         UITableViewRowAnimationLeft :
         UITableViewRowAnimationRight];
    }




    //[self addSectionAtIndex:0 withAnimation:UITableViewRowAnimationFade];
    //for (NSInteger i = 0; i < 4; i++)
    //{
    //  [self
    //      appendRowToSection:0
    //      cellClass:[LabelCell class]
    //      cellData:[NSString stringWithFormat:
    //          NSLocalizedString(@"This is row %ld", @""), i + 1]
    //      withAnimation:(i % 2) == 0 ?
    //          UITableViewRowAnimationLeft :
    //          UITableViewRowAnimationRight];
//  }

    [self addSectionAtIndex:1 withAnimation:UITableViewRowAnimationFade];
    for (NSInteger i = 0; i < 1; i++)
    {
        [self
            appendRowToSection:1
            cellClass:[NibLoadedCell3 class]
            cellData:[NSString stringWithFormat:
                NSLocalizedString(@"This is row %ld", @""), i + 1]
            withAnimation:(i % 2) == 0 ?
                UITableViewRow开发者_JAVA百科AnimationLeft :
                UITableViewRowAnimationRight];
    }

//  [self addSectionAtIndex:2 withAnimation:UITableViewRowAnimationFade];
//  for (NSInteger i = 0; i < 4; i++)
//  {
//      [self
//          appendRowToSection:2
    //      cellClass:[TextFieldCell class]
    //      cellData:
    //          [NSMutableDictionary dictionaryWithObjectsAndKeys:
    //              [NSString stringWithFormat:
    //                  NSLocalizedString(@"TextField %ld", @""), i + 1],
    //                  @"label",
    //              @"", @"value",
    //              NSLocalizedString(@"Value goes here", @""),
    //                  @"placeholder",
    //          nil]
        //  withAnimation:(i % 2) == 0 ?
    //          UITableViewRowAnimationLeft :
    //          UITableViewRowAnimationRight];
//  }

    [self addSectionAtIndex:2 withAnimation:UITableViewRowAnimationFade];
    for (NSInteger i = 0; i < 1; i++)
    {
        [self
         appendRowToSection:2
         cellClass:[NibLoadedCell class]
         cellData:[NSString stringWithFormat:
                   NSLocalizedString(@"This is row %ld", @""), i + 1]
         withAnimation:(i % 2) == 0 ?
         UITableViewRowAnimationLeft :
         UITableViewRowAnimationRight];
    }


    [self hideLoadingIndicator];
}

//
// refresh
//
// Removes all existing rows and starts a reload (on a 0.5 second timer)
//
- (void)refresh:(id)sender
{
    [self removeAllSectionsWithAnimation:UITableViewRowAnimationFade];
    [self performSelector:@selector(createRows) withObject:nil afterDelay:0.5];
    [self showLoadingIndicator];
}

//
// viewDidLoad
//
// On load, refreshes the view (to load the rows)
//
- (void)viewDidLoad
{
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
     self.title = @"Les Robes";
    [super viewDidLoad];

    self.useCustomHeaders = YES;
    [self refresh:nil];
}

//
// loadView
//
// Since the view is so simple (just a GradientBackgroundView) we might as
// well contruct it in code.
//
- (void)loadView
{
    GradientBackgroundTable *aTableView =
        [[[GradientBackgroundTable alloc]
            initWithFrame:CGRectZero
            style:UITableViewStyleGrouped]
        autorelease];

    self.view = aTableView;
    self.tableView = aTableView;
}

//
// textFieldDidEndEditing:
//
// Update the rowData for the text field rows to match the edited value of the
// text field.
//

//
// tableView:titleForHeaderInSection:
//
// Header text for the three sections
//
// Parameters:
//    aTableView - the table
//    section - the section for which header text should be returned
//
// returns the header text for the appropriate section
//
- (NSString *)tableView:(UITableView *)aTableView
    titleForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        return NSLocalizedString(@"Les Motifs", nil);
    }
    else if (section == 1)
    {
        return NSLocalizedString(@"Les Couleurs", nil);
    }
    else if (section == 2)
    {
        return NSLocalizedString(@"À Savoir", nil);
    }

    return nil;
}

@end


In your createRows method, you have a loop that will only execute once:

for (NSInteger i = 0; i < 1; i++) { ... }

Therefore, things like i + 1 and i % 2 could just be constants since i will always be 0.


for (NSInteger i = 0; i < 1; i++)

Your for loop starts at 0, ends at 0. i++ will never be executed.


You've got several loops of the form:

for (NSInteger i = 0; i < 1; i++) { }

That code is nearly meaningless, though... the code in the body of the loop will only ever execute once, while i == 0, so you might as well just take it out of the loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号