gpt4 book ai didi

ios - 如何在我的代码中添加循环

转载 作者:行者123 更新时间:2023-11-29 00:34:10 26 4
gpt4 key购买 nike

我有 NSMutableArray *arrList 并且我在 MutableArray *arrList 中创建了 Monday 对象。但现在是在 if 条件下静态编写的,在我的代码中看起来像:(if ([str containsString:@"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);

希望这能帮助您获得工作日。

关于ios - 如何在我的代码中添加循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com