更改 NSObject 定义导致无法识别的选择器

Altering NSObject Definition resulting in unrecognized selector

我正在尝试自定义 NSObject 以接受附加参数,但是每当我尝试添加它时,我都会得到:

NSInvalidArgumentException: -[TEATimeRange initWithStart:end:fill:]: unrecognized selector sent to instance`

这是 .h 文件:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface TEATimeRange : NSObject

@property (nonatomic) NSDate *start;
@property (nonatomic) NSDate *end;
@property (nonatomic) IBInspectable UIColor *fill;

+ (instancetype)timeRangeWithStart:(NSDate *)startTime end:(NSDate *)endTime fill:(UIColor *)fillColor;

- (id)initWithStart:(NSDate *)startTime end:(NSDate *)endTime fill:(UIColor *)fillColor;

@end

.m 文件:

#import "TEATimeRange.h"

@implementation TEATimeRange

+ (instancetype)timeRangeWithStart:(NSDate *)startTime end:(NSDate *)endTime fill:(UIColor *)fillColor
{
    return [[TEATimeRange alloc] initWithStart:startTime end:endTime fill:fillColor];
}

- (id)initWithStart:(NSDate *)startTime end:(NSDate *)endTime fill:(UIColor *)fillColor
{
    self = [super init];
    if (self) {
        _start = startTime;
        _end = endTime;
        _fill = fillColor;
    }
    return self;
}

@end

调用实例(在Swift):

TEATimeRange(start: someDateTime, end: someDateTime?.addingTimeInterval(TimeInterval(someTime)), fill: .orange)

如果我删除对 fill: 的引用,它会按预期运行,所以我很困惑为什么。

我尝试了 SO 搜索,但由于我只有 3 天的 iOS 开发经验,所以我找不到任何解决方案,因此非常感谢您的帮助。 (即使这是一件愚蠢的事情!)

对于访问此页面的未来开发者,我的问题已通过以下方式解决:

  1. 清理构建文件夹(产品 > 清理构建文件夹或 K
  2. 正在重启Xcode
  3. 重新运行申请

如果这不起作用,请参阅上面@OOPer 和@rmaddy 的评论以获得进一步指导