- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 EventKit 的
EKEventStore
,我想模拟它和 EKEvent。但是我不知道如何正确抽象EKEvent's
init(eventStore: EKEventStore)
和其他方法。
protocol EventStoring {
associated type Event: EventStoreEvent where Event.MatchingEventStore == Self
func save(_ event: Event, span: EKSpan, commit: Bool) throws
// Other methods of EKEventStore I use
}
extension EKEventStore: EventStoring {
typealias Event = EKEvent
}
protocol EventStoreEvent {
associatedtype MatchingEventStore: EventStoring
static func createEvent(eventStore: MatchingEventStore) -> Self
}
extension EKEvent: EventStoreEvent {
typealias MatchingEventStore = EKEventStore
static func createEvent(eventStore: MatchingEventStore) -> Self {
return EKEvent(eventStore: eventStore) as! Self
}
}
此处的错误是:“'Self' 仅在协议(protocol)中可用或作为类中方法的结果可用;您是说 'EKEvent'
吗?”并且:“无法将类型 'EKEvent'
的返回表达式转换为返回类型'Self'”
class GenericEventManger<StoreEvent: EventStoreEvent> {
var store: EventStoring
required init(with eventStore: EventStoring) {
self.store = eventStore
}
func createEvent() -> StoreEvent {
let eventStoreEvent: EventStoreEvent = StoreEvent.createEvent(eventStore: store)
// Then some code where I configure the event...
try store.save(eventStoreEvent, span: .thisEvent, commit: true)
}
}
在倒数第七行,错误是:无法使用 '(eventStore: EventStoring)' 类型的参数列表调用
在倒数第三个是:无法使用 'createEvent'
'(StoreEvent, span: EKSpan, commit: Bool)' 类型的参数列表调用 'save'
更新 由于我采纳了 Dan 的建议,在我的实现过程中出现了另一个同类问题,所以我更新了我的问题
最佳答案
我想在 Dan 的帮助下,到目前为止我已经找到了两个问题的解决方案,但我还没有彻底测试它:
首先,我按照 Dan 的建议更改了 GenericStoreManager
的 store
属性的类型
class GenericStoreManger<StoreEvent: EventStoreEvent> {
var store: StoreEvent.MatchingEventStore
func createEvent() -> StoreEvent {
let eventStoreEvent: EventStoreEvent = StoreEvent.createEvent(eventStore: store)
// Then some code where I configure the event...
try store.save(eventStoreEvent as! StoreEvent.MatchingEventStore.Event, span: .thisEvent, commit: true)
}
...
}
然后我更改了在 extension EKEvent: EventStoreEvent
中获取返回值的方式,因此它也可以在 EKEvent 的子类中工作
extension EKEvent: EventStoreEvent {
typealias MatchingEventStore = EKEventStore
static func createEvent(eventStore: MatchingEventStore) -> Self {
return self.init(eventStore: eventStore)
}
}
关于swift - 如何使用类型为 "Cannot invoke ' 的参数列表修复 '(eventStore: EventStoring)' createEvent',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54406371/
我有以下代码: Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub SetStat
在调用 Invoke-RestMethod 时使用 Powershell,例如: Invoke-RestMethod -Method Get -Uri "https://google.com/api/
我正在尝试将 Winform 应用程序转换为控制台应用程序。 Winform 应用程序有一个委托(delegate)处理程序。如何在 console 应用程序中编写相同的功能? this.Invoke
在 WPF 中,Dispatcher.Invoke 和直接在控件实例上调用的 Invoke 有什么区别。据我了解,调度程序负责处理线程的消息,Control.Invoke 是否会继续调用 Dispat
我正在研究性能监控系统,它可以将其例程注入(inject)现有程序集。为此,我试图了解 dalvik 代码的工作原理。 下面是我要完成的工作的示例。输入类可能如下所示: class MyClass{
我正在使用 powershell 命令来执行脚本和 cmdlet。因此,在执行 cmdlet 时,我使用了 powershell.invoke,而在执行脚本时,我使用了 pipeline.invoke
有人能解释一下 Invoke-Expression $test 之间的区别吗?和 Invoke-Expression -Command $test ? 变量测试是: $test = "notepad
我有四个类,即 MapperOne、ReducerOne、MapperTwo、ReducerTwo。我想要其中的一个链。 MapperOne-->ReducerOne-->输出文件生成,输入到Mapp
我正在阅读 Java ForkJoin 框架。不直接在 ForkJoinTask 的实现上调用 invoke()(例如 RecursiveTask),而是实例化 ForkJoinPool 有什么额外的
我在调用 Invoke-SqlCmd 时遇到问题,因为它包含第二个 Invoke-SqlCmd 调用: function Get-Foo { $query=` @" WITH data AS (
有人知道如何解决这个问题吗?我创建了一个客户端来使用网络服务。客户端代码为: package cliente; import java.util.List; import handler.Header
我希望使用 P/Invoke 来允许我的 C# 程序集与 native C 库互操作;这需要是跨平台的(即 Mono),因此不能使用混合模式程序集。我想知道使用不安全的 P/invoke 调用并在不安
一般来说,我对使用 Invoke-RestMethod/Invoke-WebRequest 比较陌生 - 我认为这是以下问题的重要背景。 我正在调用如下电话: $Headers = @{ "A
在 Jenkins 的一个自由风格项目(不是说 Maven2/3 项目)中,我有两个可能的构建步骤: 调用 Maven 3 调用顶级 Maven 目标 在不同的安装中,我有不同的组合(有些两者都有,有
这是完整的错误: e: C:\Users\HP\AndroidStudioProjects\MoneyManager\app\src\main\java\com\cruxrepublic\moneym
我正在编写 jQuery 插件并将它们与 AJAX 集成。我正在减少脂肪并专注于基础知识: (function($) { function MyPlugin(el, options) {
有人可以建议我如何处理这条消息吗? CA1060 Move P/Invokes to NativeMethods class Because it is a P/Invoke method, 'UCo
在java中我们可以“用类名调用一个静态方法”也可以“用一个对象调用一个静态方法”java中“用类名调用静态方法”和“用对象调用静态方法”有什么区别? 最佳答案 没有区别,但建议以静态方式调用 sta
尝试从对话框中的 EditText 获取 Edit Text 的值,但一次又一次地出现此错误 Attempt to invoke virtual method 'android.text.Editab
我正在开发一款扑翼应用程序。在出现此错误之前,读取和写入FireStore数据库没有任何问题,但随后突然出现错误(如下所示),并阻止我读取或写入数据库。我一直在寻找答案,但不幸的是,我找不到任何可以解
我是一名优秀的程序员,十分优秀!