我正在尝试在 Swift 中扩展一个 Objective-C 类并使其符合Equatable
协议。这需要访问扩展类的一些私有成员,编译器不允许我这样做。不公开私人成员的正确方法是什么?
我的斯威夫特代码:
import Foundation
extension ShortDate : Equatable { }
public func == (lhs: ShortDate, rhs: ShortDate) -> Bool {
if (lhs.components.year == rhs.components.year)
&& (lhs.components.month == rhs.components.month)
&& (lhs.components.day == rhs.components.day) {
return true;
}
return false;
}
目标-C:
@interface ShortDate : NSObject<NSCopying, NSCoding> {
NSDate *inner;
NSDateComponents *components; // The date split into components.
}
...
@end
我得到的错误:
ShortDate.swift:26:9:“ShortDate”没有名为“组件”的成员