ios - 更改 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 开发经验,我无法找到任何解决方案,因此将不胜感激。(即使这是一件愚蠢的事情!)
解决方案
对于访问此页面的未来开发人员,我的问题已通过以下方式解决:
- 清理构建文件夹(产品 > 清理构建文件夹或⇧</kbd> ⌘</kbd> K)
- 重启 Xcode
- 重新运行应用程序
如果这不起作用,请参阅上面来自 @OOPer 和 @rmaddy 的评论以获得进一步的指导
推荐阅读
- hadoop - 如何使用 hive 在本地文件系统(不是 hdfs)上读取 CSV?
- r - 仅从第 n 个 epoch 开始绘制训练运行损失和指标
- r - 列出 r 中的名称和值
- laravel-5 - 在 laravel 中动态更改配置值
- javascript - Mailto 链接在 contentEditable 中未触发
- react-native - 在 React Native Maps 中设置最大和最小缩放级别
- php - 从数组中排除第一个结果
- node.js - 如何在 ejs 中为动态 url 提供静态文件?
- zpl - ZPL 代码获取副本数 #of10
- html - 使用自定义表单创建令牌