[英]Can;t define and use protocol
我正在尝试将一些Objective-C代码迁移到我的Swift代码,但是Swift中存在一些协议错误。 在我的Objective-C中,所有功能都完美运行。
我有一类说MGCDayPlannerEKViewController,
public class MGCDayPlannerEKViewController : MGCDayPlannerViewController, UIPopoverPresentationControllerDelegate {
public var calendar: NSCalendar!
public var visibleCalendars: Set<NSObject>!
public var eventStore: EKEventStore! { get }
weak public var delegate: MGCDayPlannerEKViewControllerDelegate!
/** designated initializer */
public init!(eventStore: EKEventStore!)
public func reloadEvents()
}
public protocol MGCDayPlannerEKViewControllerDelegate : NSObjectProtocol {
@available(iOS 4.0, *)
optional public func dayPlannerEKEViewController(vc: MGCDayPlannerEKViewController!, willPresentEventViewController eventViewController: EKEventViewController!)
@available(iOS 4.0, *)
optional public func dayPlannerEKViewController(vc: MGCDayPlannerEKViewController!, navigationControllerForPresentingEventViewController eventViewController: EKEventViewController!) -> UINavigationController!
}
在我的Swift类中,我继承了该类,还在新类中创建了一个协议
protocol WeekViewControllerDelegate :MGCDayPlannerEKViewControllerDelegate,CalendarViewControllerDelegate,UIViewControllerTransitioningDelegate {
}
class WeekViewController: MGCDayPlannerEKViewController {
var delegate: WeekViewControllerDelegate?
var showDimmedTimeRanges = false
var isiPad : Bool {
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
return true
}else{
return false
}
}
}
但是我在委托声明中出现错误。 错误是
Property 'delegate' with type 'WeekViewControllerDelegate?' cannot override a property with type 'MGCDayPlannerEKViewControllerDelegate!' (aka 'ImplicitlyUnwrappedOptional<MGCDayPlannerEKViewControllerDelegate>')
我究竟做错了什么?
此错误意味着您的父类中有一个与其子类同名的属性。 在您的代码中, WeekViewController
和MGCDayPlannerEKViewController
具有一个名为delegate
的属性。 您需要在类MGCDayPlannerEKViewController
或WeekViewController
重命名变量delegate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.