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

标签 ios objective-c swift nsobject

我正在尝试自定义一个 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 开发经验,我还没有找到任何解决方案,因此非常感谢任何帮助。 (即使这是一件愚蠢的事情!)

最佳答案

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

  1. 清理构建文件夹(产品 > 清理构建文件夹或 K)
  2. 重新启动 Xcode
  3. 重新运行应用

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

关于ios - 更改 NSObject 定义导致无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55698718/

相关文章:

iPhone:我如何理解文本是否适合标签

iphone - 如何在 iphone 的 ScrollView 中将中间按钮比其他按钮高 5px

iphone - 如何在 iOS 中重新加载我的 View

ios - 通知中心 - 显示和隐藏启动栏

ios - 无法解锁钥匙串(keychain)

swift : Add image to scopebar in uiSearchbar instead of titles

swift - 我想将 func internetChanged 放在另一个文件中。 (关于可达性)

ios - 暂停按钮在更改时添加新节点

ios - 打印出连接的字符串显示(空)

ios - 如何在 Swift 中动态生成注释图像