A history of iOS code evolution

This is an interesting piece of code:

First stage:

NSArray *tabBarItems=self.tabBar.items;

UITabBarItem *indexItem = [tabBarItems objectAtIndex:0];

indexItem.title=@"home page";

indexItem.image=[UIImage imageNamed:@"menu_01_normal"];

UITabBarItem *categoryItem = [tabBarItems objectAtIndex:1];


indexItem.image=[UIImage imageNamed:@"menu_02_normal"];

UITabBarItem *customerItem=[tabBarItems objectAtIndex:1];

customerItem.title=@"Shopping Cart";

customerItem.image=[UIImage imageNamed:@"menu_03_normal"];

UITabBarItem *messageItem=[tabBarItems objectAtIndex:2];


messageItem.image=[UIImage imageNamed:@"menu_04_normal"];

UITabBarItem *mineItem=[tabBarItems objectAtIndex:3];


mineItem.image=[UIImage imageNamed:@"menu_05_normal"];

The second stage:

NSArray *tabBarItems=self.tabBar.items;

NSArray * title = @[@"home page",@"classification",@"Shopping Cart",@"news",@"My"];

for (int i = 0; i < 5; i++) {

UITabBarItem *indexItem = [tabBarItems objectAtIndex:i];

indexItem.title=[title objectAtIndex:i];

indexItem.image=[UIImage imageNamed:[NSString stringWithFormat:@"menu_0%d_normal",i + 1]];


The third stage:

NSArray *tabBarItems=self.tabBar.items;

NSArray * title = @[@"home page",@"classification",@"Shopping Cart",@"news",@"My"];

[tabBarItems enumerateObjectsUsingBlock:^(UITabBarItem * indexItem, NSUInteger idx, BOOL *stop) {

indexItem.title=[title objectAtIndex:idx];

indexItem.image=[UIImage imageNamed:[NSString stringWithFormat:@"menu_0%ld_normal",idx+1]];


Can you see how to evolve and what are the benefits!

Give me a compliment for what I see!

After watching the program that doesn't give praise, apes work overtime every day!

Don't complain about low wages, think about it!


-If you have any questions, you can discuss them together in the comment area;

-If there is anything wrong, welcome to guide!

>Note: This article was first published in iHTCboy's blog , if reproduced, please indicate the source.

Keywords: iOS

Added by Pointybeard on Fri, 13 Dec 2019 18:40:20 +0200