私は iPhone 向けの開発を始めているので、オンラインでさまざまなチュートリアルを調べたり、自分でさまざまなことを試したりしています。現在、真夜中までのカウントダウンを作成しようとしています。時、分、秒の数を取得するには、次のようにします (どこかで見つけました)。
NSDate* now = [NSDate date];
int hour = 23 - [[now dateWithCalendarFormat:nil timeZone:nil] hourOfDay];
int min = 59 - [[now dateWithCalendarFormat:nil timeZone:nil] minuteOfHour];
int sec = 59 - [[now dateWithCalendarFormat:nil timeZone:nil] secondOfMinute];
countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, min,sec];
ただし、使用する場所ごと-dateWithCalendarFormat:timeZone:
に次のエラーが発生します。
warning: 'NSDate' may not respond to '-dateWithCalendarFormat:timeZone:'
(Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)
warning: no '-hourOfDay' method found
error: invalid operands to binary - (have 'int' and 'id')
これは非常に単純なことのように思えます。私は何が欠けていますか?
NSDate* now
また、さまざまな場所とさまざまな時間に、アスタリスク (*) が時間の直後または variable の直前にあることに気付きましたNSDate *now
。この 2 つの違いは何ですか? また、どちらを使用するのですか?