ios - xCode 7 + Swift 2.0 中的编译错误

标签 ios xcode swift swift2 xcode7-beta2

自从我安装了 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/

相关文章:

objective-c - 无法在iOS中实现简单的 View 滚动

ios - 无法将 View Controller 属性获取到另一个 View Controller

ios - 在 iOS 应用程序运行时更新资源

xcode - Xcode 的 PackageApplication 的替代品是什么?

iOS XMPP 在对话屏幕中收到消息

ios - 由于来自广告商框架的意外 CFBundleExecutable key ,来自 Xcode 7.0.1 的二进制文件未上传

swift - 如何将 "Text(example1: "ex 1", example2: "ex 2")"转换为可用的字典

swift - 从已点击的 mapView MKAnnotation 通过 Segue 传递数据

Swift UIPasteboard 不复制 PNG

iphone - 无法在 Xcode 中选择文件所有者