我正在尝试使用NSDateComponents
获取当前日期。 (然后我将改变周,月等。)这是代码:
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [calendar component:(NSCalendarUnitCalendar |
NSCalendarUnitYear |
NSCalendarUnitMonth |
NSCalendarUnitDay) fromDate:[NSDate date]];
Xcode
给了我以下警告:
Incompatible integer to pointer conversion initializing 'NSDateComponents *__string' with an expression of type...'
错误:
Implicit conversion of 'NSInteger' (aka 'long') to 'NSDateComponents *' is disallowed with ARC
答案 0 :(得分:1)
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
使用component
添加您要访问的1个单元。
将components
用于多个单元。