これを行うためのより良い方法はありますか?
-(NSDate *)getMidnightTommorow {
NSCalendarDate *now = [NSCalendarDate date];
NSCalendarDate *tomorrow = [now dateByAddingYears:0 months:0 days:1 hours:0 minutes:0 seconds:0];
return [NSCalendarDate dateWithYear:[tomorrow yearOfCommonEra]
month:[tomorrow monthOfYear]
day:[tomorrow dayOfMonth]
hour:0
minute:0
second:0
timeZone:[tomorrow timeZone]];
}
その電話をかけるときにたまたま真夜中であっても、常に次の真夜中が欲しいことに注意してください。ただし、23:59:59の場合は、もちろん1秒で来る真夜中が欲しいです。
自然言語の機能は不安定に見えます。「日」フィールドで32を渡すと、Cocoaが何をするかわかりません。(それがうまくいけば、[now dateByAddingYears:...]呼び出しを削除できます)