<分区>
我正在尝试学习一些 Swift 语言,我想知道如何将以下 Objective-C 转换为 Swift:
- (void)refreshDataOnChange {
if (![tblSkillMaterials.delegate isKindOfClass:[self class]]) {
tblSkillMaterials.delegate = self;
}
if (![tblSkillMaterials.dataSource isKindOfClass:[self class]]) {
tblSkillMaterials.dataSource = self;
}
//Other Code Logic Here
}
更具体地说,我需要知道如何在新语法中使用 isKindOfClass。
func refreshDataOnChange() {
if tblSkillMaterials.delegate?.isKind(of: ?) {
tblSkillMaterials.delegate = self
}
if tblSkillMaterials.dataSource?.isKind(of: ?) {
tblSkillMaterials.dataSource = self
}
//Other Code Logic Here
}
获取错误如:
Cannot convert value of type 'ViewController' to expected argument type 'AnyClass' (aka 'AnyObject.Type')