gpt4 book ai didi

iphone - Objective-C Expected Identifier - 简单语法调试问题

转载 作者:行者123 更新时间:2023-12-03 20:26:02 27 4
gpt4 key购买 nike

我需要帮助调试此错误预期标识符。代码是-

+(NSString *)dayOfWeek {
NSDate *day = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:NSWeekdayCalendarUnit fromDate:day];
day = [calendar dateFromComponents:components];
NSLog(@"The DAY OF THE WEEK is -- %@", day);
NSArray *daysOfTheWeek = [NSArray arrayWithObjects:@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday", nil];

NSString *dayName = [[[NSString alloc] initWithFormat:[daysOfTheWeek objectAtIndex:[[components weekday]-1]]]];
return dayName;
}

我在 ] 下方的 -1] 处看到错误标记。

最佳答案

我认为这一行:

NSString *dayName = [[[NSString alloc] initWithFormat:[daysOfTheWeek objectAtIndex:[[components weekday]-1]]]];

应该看起来像这样:

NSString *dayName = [[NSString alloc] initWithString:[daysOfTheWeek objectAtIndex:[components weekday]-1]];

由于编译器警告,我更改了 initWithFormat。您没有替换任何内容,因此 initWithString 应该足以开始。

关于iphone - Objective-C Expected Identifier - 简单语法调试问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5895168/

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