我正在尝试在
Swift中扩展一个Obj-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; }
Objective-C的:
@interface ShortDate : NSObject<NScopying,NSCoding> { NSDate *inner; NSDateComponents *components; // The date split into components. } ... @end
错误:
ShortDate.swift:26:9: ‘ShortDate’ does not have a member named ‘components’
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。