首页 > 解决方案 > 如何将 UIDropSession 用于 Apple 日历事件?

问题描述

开始实现拖放,大部分只是拖放,添加拖放图像、联系人、字符串在日历事件中被阻止

所以我的代码如下所示:

func addDropInteraction() {
    let dropInteraction = UIDropInteraction(delegate: self)
    view.addInteraction(dropInteraction)
}

public func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool {
    return session.hasItemsConforming(toTypeIdentifiers: [kUTTypeCalendarEvent as String]) && session.items.count == 1
}

public func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {
    return UIDropProposal(operation: .copy)
}

public func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {

}

唯一的问题是我在实现时无法加载类型的EKEvent对象EKECalendarItem

session.loadObjects(ofClass: EKEvent.self) { eventItems in
        let events = eventItems as! [EKEvent]
    }

performDrop session:我收到一个错误:

Instance method 'loadObjects(ofClass:completion:)' requires that 'EKEvent' conform to '_ObjectiveCBridgeable'

所以我的问题是如何加载日历事件?

标签: swifteventkitekeventuidragitemuidraginteraction

解决方案


推荐阅读