gpt4 book ai didi

ios - IOS中没有可见的@interface声明选择器 'ordinalityOfUnit:inUnit:forDate:'

转载 作者:行者123 更新时间:2023-11-28 22:21:54 24 4
gpt4 key购买 nike

我尝试计算两个 NSDate 之间的天数我使用了这个 https://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/DatesAndTimes/Articles/dtCalendricalCalculations.html

Listing 13 Days between two dates, as the number of midnights between

@implementation NSCalendar (MySpecialCalculations)

-(NSInteger)daysWithinEraFromDate:(NSDate *) startDate toDate:(NSDate *) endDate
{
NSInteger startDay=[self ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:startDate];
NSInteger endDay=[self ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:endDate];
return endDay-startDay;
}
@end

这是我的代码:

@implementation MapViewController
-(NSInteger)daysWithinEraFromDate:(NSDate *) startDate toDate:(NSDate *) endDate
{
NSInteger startDay=[self ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:startDate];
NSInteger endDay=[self ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:endDate];
return endDay-startDay;
}

- (void)viewDidLoad
{
[super viewDidLoad];
}

@end

但是我遇到了这个错误。请帮助我!!

 No visible @interface for 'MapViewController' declares the selector 'ordinalityOfUnit:inUnit:forDate:'

最佳答案

像这样使用:

[[NSCalendar currentCalendar] ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:startDate];

关于ios - IOS中没有可见的@interface声明选择器 'ordinalityOfUnit:inUnit:forDate:',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20126159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com