如何在我的代码中添加循环
How to add loop in my code
我有 NSMutableArray *arrList
并且我在 MutableArray *arrList
中创建了 星期一 个对象。但是现在是静态写在 if 条件下,在我的代码中看起来像:(if ([str containsString:@"Monday"])
)。我想要一个数组加载位置到静态 Monday。这意味着在静态星期一逐周循环加载。
NSArray*loopAry = [[NSArray alloc]initWithObjects:@"Sunday",@"Monday",@"Tuesday",nil];
也就是loopAry
对象一个接一个地重新加载到放置静态星期一。
这有助于获取动态代码并在循环中仅重新加载数组并获取工作日数据
NSMutableArray *arrList = [[NSMutableArray alloc]initWithObjects:@"25-11-2016, Friday",
@"26-11-2016, Saturday",
@"27-11-2016, Sunday",
@"28-11-2016, Monday",
@"29-11-2016, Tuesday",
@"30-11-2016, Wednesday",
@"01-12-2016, Thursday",
@"02-12-2016, Friday",
@"03-12-2016, Saturday",
@"04-12-2016, Sunday",
@"05-12-2016, Monday",
@"06-12-2016, Tuesday",
@"07-12-2016, Wednesday", nil];
NSMutableArray *result = [[NSMutableArray alloc]init];
for (id element in arrList){
NSString *str = element;
if ([str containsString:@"Monday"]) {
[result addObject:element];
}
}
// print result
NSLog(@"%@",result);
(
"28-11-2016, Monday",
"05-12-2016, Monday"
)
您可以获得如下提供的日期数组:
NSArray *loopAry = [[NSArray alloc]initWithObjects:@"Sunday",@"Monday",@"Tuesday",nil];
NSMutableArray *arrList = [[NSMutableArray alloc]initWithObjects:@"25-11-2016, Friday",
@"26-11-2016, Saturday",
@"27-11-2016, Sunday",
@"28-11-2016, Monday",
@"29-11-2016, Tuesday",
@"30-11-2016, Wednesday",
@"01-12-2016, Thursday",
@"02-12-2016, Friday",
@"03-12-2016, Saturday",
@"04-12-2016, Sunday",
@"05-12-2016, Monday",
@"06-12-2016, Tuesday",
@"07-12-2016, Wednesday", nil];
NSMutableArray *result = [[NSMutableArray alloc]init];
for (NSString *strData in arrList){
//2nd Loop for your weekdays array.By this you will get weekdays array in result.
for (NSString *strDay in loopAry) {
if ([strData containsString:strDay]) {
[result addObject:strData];
}
}
}
// print result
NSLog(@"%@",result);
希望这对您获得工作日有所帮助。
我有 NSMutableArray *arrList
并且我在 MutableArray *arrList
中创建了 星期一 个对象。但是现在是静态写在 if 条件下,在我的代码中看起来像:(if ([str containsString:@"Monday"])
)。我想要一个数组加载位置到静态 Monday。这意味着在静态星期一逐周循环加载。
NSArray*loopAry = [[NSArray alloc]initWithObjects:@"Sunday",@"Monday",@"Tuesday",nil];
也就是loopAry
对象一个接一个地重新加载到放置静态星期一。
这有助于获取动态代码并在循环中仅重新加载数组并获取工作日数据
NSMutableArray *arrList = [[NSMutableArray alloc]initWithObjects:@"25-11-2016, Friday",
@"26-11-2016, Saturday",
@"27-11-2016, Sunday",
@"28-11-2016, Monday",
@"29-11-2016, Tuesday",
@"30-11-2016, Wednesday",
@"01-12-2016, Thursday",
@"02-12-2016, Friday",
@"03-12-2016, Saturday",
@"04-12-2016, Sunday",
@"05-12-2016, Monday",
@"06-12-2016, Tuesday",
@"07-12-2016, Wednesday", nil];
NSMutableArray *result = [[NSMutableArray alloc]init];
for (id element in arrList){
NSString *str = element;
if ([str containsString:@"Monday"]) {
[result addObject:element];
}
}
// print result
NSLog(@"%@",result);
(
"28-11-2016, Monday",
"05-12-2016, Monday"
)
您可以获得如下提供的日期数组:
NSArray *loopAry = [[NSArray alloc]initWithObjects:@"Sunday",@"Monday",@"Tuesday",nil];
NSMutableArray *arrList = [[NSMutableArray alloc]initWithObjects:@"25-11-2016, Friday",
@"26-11-2016, Saturday",
@"27-11-2016, Sunday",
@"28-11-2016, Monday",
@"29-11-2016, Tuesday",
@"30-11-2016, Wednesday",
@"01-12-2016, Thursday",
@"02-12-2016, Friday",
@"03-12-2016, Saturday",
@"04-12-2016, Sunday",
@"05-12-2016, Monday",
@"06-12-2016, Tuesday",
@"07-12-2016, Wednesday", nil];
NSMutableArray *result = [[NSMutableArray alloc]init];
for (NSString *strData in arrList){
//2nd Loop for your weekdays array.By this you will get weekdays array in result.
for (NSString *strDay in loopAry) {
if ([strData containsString:strDay]) {
[result addObject:strData];
}
}
}
// print result
NSLog(@"%@",result);
希望这对您获得工作日有所帮助。