我想从日期获取 NSString,日期格式如下:
MMEEEY ww
Run Code Online (Sandbox Code Playgroud)
问题出在“ww”,即一年中的第几周。我必须将此格式与从后台获取的另一种格式进行比较。但后台的第一个工作日是星期一,而 iOS 的第一个工作日是星期日。因此,当星期日时,字符串会不同,因为一年中的星期不同。
问题是: 如何强制 NSDateFormatter 使用星期一作为第一个工作日?
我尝试使用将firstWeekday属性设置为2的日历来设置NSDateFormatter的日历属性,但它不起作用。
其要点是:
NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
calendar.firstWeekday = 2;
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.calendar = calendar;
Run Code Online (Sandbox Code Playgroud)
编辑:诺亚回答后的测试
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
dateFormatter.locale = locale;
dateFormatter.dateFormat = @"MMEEEY ww";
NSDate * date = [NSDate dateWithTimeIntervalSince1970:1330251642]; // next sunday
NSLog(@"%@ -> %@", date, [dateFormatter stringFromDate:date]);
NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
calendar.firstWeekday = …Run Code Online (Sandbox Code Playgroud) 我最近完成了从 AudioKit 3.7 到 4.2 的迁移(使用 Cocoapods),这是 XCode 9.3 所需的。我按照迁移指南将 AKAudioPlayer 更改为 AKPlayer。
当 AKPlayer 播放音频文件时,AudioKit 崩溃并出现以下错误:
2018-04-17 09:32:43.042658+0200hearfit[3509:2521326][avae]AVAEInternal.h:103:_AVAE_CheckNoErr:[AVAudioEngineGraph.mm:3632:UpdateGraphAfterReconfig:(AUGraphParser::InitializeActiveNodesInOutputChain(ThisGraph, kOutputChainFull)遍历,*conn .srcNode,isChainActive)):错误-10875 2018-04-17 09:32:43.049372+0200hearfit[3509:2521326]*** 由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“错误-10875” *** 首先抛出调用堆栈: (0x1847d6d8c 0x1839905ec 0x1847d6bf8 0x18a0ff1a0 0x18a11bf58 0x18a12aab0 0x18a128cdc 0x18a1a1738 0x18a1a160c 0x10519192c 0x10519 d2f4 0x10519d64c 0x10503afdc 0x10507c4a0 0x10507c01c 0x104f6d9cc 0x1852233d4 0x18477faa8 0x18477f76c 0x18477f010 0x18477cb60 0x18 469cda8 0x18667f020 0x18e67d78c 0x10504dfd4 0x18412dfc0) libc++abi.dylib:以 NSException 类型的未捕获异常终止
有时它发生在第一次播放时,有时第一次播放正确,但第二次播放则不然。
迁移之前一切都运行良好。我还尝试保留 AKAudioPlayer: 声音正常播放,但 AKFrequencyTracker 不再工作。
这是我的设置:
AKPlayer 1播放短音频文件(1 到 5 秒之间)AKFrequencyTracker用于显示绘图AKPlayer 2播放背景声音(音量必须可配置)AKWhiteNoise允许进行一些手动体积测量(使用 …