自从我安装了 xCode 7 beta2 + Swift 2.0 后,我的应用程序出现了一些错误。例如,我收到以下错误
"Cannot invoke 'requestAccessToEntityType' with an argument list of type '(EKEntityType, completion: (Bool, NSError!) -> _)'
这部分代码:
eventStore.requestAccessToEntityType(EKEntityType.Event,
completion: {(granted: Bool, error:NSError!) in
if !granted {
print("Access to store not granted")
}
})
还有这个错误:
Cannot invoke 'predicateForEventsWithStartDate' with an argument list of type '(NSDate, endDate: NSDate, calendars: [AnyObject])'
这部分代码:
calendarsPrueba.addObject(calendarWithName("US Holidays")!)
var predicate2 = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: calendarsPrueba as [AnyObject])
有人知道如何解决这个问题吗?没有关于此的 Apple 文档
最佳答案
与@HAS 提出的问题相同 - 您是否运行了迁移器? Swift 1.2 和 Swift 2.0 之间有很多不兼容的变化。必须迁移或手动修复代码。
requestAccessToEntityType
错误...
Cannot invoke 'requestAccessToEntityType' with an argument list of type '(EKEntityType, completion: (Bool, NSError!) -> _)'
... 是因为您的类型是 (Bool, NSError!) -> Void
而不是 (Bool, NSError?) -> Void
。将 NSError!
替换为 NSError?
以修复它。
检查文档,签名为:
typealias EKEventStoreRequestAccessCompletionHandler = (Bool, NSError?) -> Void
predicateForEventsWithStartDate
Cannot invoke 'predicateForEventsWithStartDate' with an argument list of type '(NSDate, endDate: NSDate, calendars: [AnyObject])'
签名是:
func predicateForEventsWithStartDate(_ startDate: NSDate,
endDate endDate: NSDate,
calendars calendars: [EKCalendar]?) -> NSPredicate
使用您的as [AnyObject]
,您试图传递[AnyObject]
而不是[EKCalendar]
。要解决此问题,请将 calendarsPrueba
声明为:
var calendarsPrueba: [EKCalendar]
并且不要将其转换为 [AnyObject]
。
Do somebody know how to fix this issues? There's no Apple documentation about this
有。始终阅读发行说明,您可以在其中找到所有更改的摘要。然后重新检查文档,因为正如我所写,您会发现 Swift 1.2 和 Swift 2.0 之间有许多重大变化。
关于ios - xCode 7 + Swift 2.0 中的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31087340/