2016-12-28 100 views
-1

我想將一些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! 
} 

在我的雨燕類,我繼承這個類,並創建我的新類

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>') 

我在做什麼錯?

回答

3

此錯誤意味着在您的父類中有一個與它的子項名稱相同的屬性。在您的代碼WeekViewControllerMGCDayPlannerEKViewController有一個屬性稱爲delegate。您需要重命名類別MGCDayPlannerEKViewControllerWeekViewController中的變量delegate