I am trying to extend the Obj-C class in Swift and make it compatible with the Equatable protocoll. This requires access to some private members of the extended class, which the compiler does not allow me. What is the right way to do this without opening private members?
Swift:
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;
}
Objective-C:
@interface ShortDate : NSObject<NSCopying, NSCoding> {
NSDate *inner;
NSDateComponents *components;
}
...
@end
Error:
ShortDate.swift: 26: 9: "ShortDate" does not have a member named "components"
source
share