私はiOSを初めて使用し、メソッドを記述しているときにiOSのパターンに従うのに少し問題があります。私はobjective-cを使用して日付の値をインクリメントする簡単な方法を見つけようとしています。
考慮事項:
NSInteger incrementType = 1; // from 1 to 4, days, weeks, months, year
NSInteger incrementSize = 20 // the increment size
NSDate* date = ... // some date
+(NSDate*)somename:(NSInteger)incrementSize type:(NSInteger)incrementType current:(NSDate*)date {
NSCalendar* gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents* ateComponents = [[NSDateComponents alloc] init];
// switch
[weekdayComponents setMonth:incrementSize];
NSDate* newDate = [gregorian dateByAddingComponents:dateComponents toDate:date options:0];
return newDate;
}
問題:
- 論理が正しいかどうかはわかりません。stackoverflowでコードの一部を見つけ、それを変更しようとしています。
- 増分タイプパラメーターの列挙型を作成するにはどうすればよいですか?
- 良いメソッドシグネチャは何でしょうか?