xCode 7 + Swift 2.0中的编译错误 [英] Compilation errors in xCode 7 + Swift 2.0

查看:133
本文介绍了xCode 7 + Swift 2.0中的编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我已经安装了xCode 7 beta2 + Swift 2.0,因此我的应用程序出现了一些错误.例如,我收到以下错误

Since I have installed the xCode 7 beta2 + Swift 2.0, I'm getting some errors in my app. For example, I'm getting the following error

无法使用类型为'(EKEntityType,完成:(Bool,NSError!)-> _)'>的参数列表调用'requestAccessToEntityType'

"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")
            }
    })

此错误:

不能使用类型为((NSDate,endDate:NSDate,calendars:[AnyObject])')的参数列表调用'predicateForEventsWithStartDate'

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文档

Do somebody know how to fix this issues? There's no Apple documentation about this

推荐答案

与@HAS相同的问题-您是否运行了迁移器? Swift 1.2和Swift 2.0之间存在许多不兼容的更改.代码必须迁移或手动修复.

Same question as @HAS had - did you run the migrator? Lot of incompatible changes between Swift 1.2 and Swift 2.0. Code must be migrated or manually fixed.

requestAccessToEntityType

requestAccessToEntityType

错误...

无法使用以下参数列表调用"requestAccessToEntityType" 键入'((EKEntityType,完成:(Bool,NSError!)-> _)'

Cannot invoke 'requestAccessToEntityType' with an argument list of type '(EKEntityType, completion: (Bool, NSError!) -> _)'

...在那里,因为您的类型是(Bool, NSError!) -> Void而不是(Bool, NSError?) -> Void.用NSError?替换NSError!进行修复.

... is there because your type is (Bool, NSError!) -> Void instead of (Bool, NSError?) -> Void. Replace NSError! with NSError? to fix it.

检查文档,签名为:

typealias EKEventStoreRequestAccessCompletionHandler = (Bool, NSError?) -> Void

predicateForEventsWithStartDate

predicateForEventsWithStartDate

无法通过参数列表调用'predicateForEventsWithStartDate' 类型为((NSDate,endDate:NSDate,Calendars:[AnyObject])'

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声明为:

With your as [AnyObject] you're trying to pass [AnyObject] instead of [EKCalendar]. To fix this, declare calendarsPrueba as:

var calendarsPrueba: [EKCalendar]

并且不要将其强制转换为[AnyObject].

And do not cast it to [AnyObject].

有人知道如何解决此问题吗?没有苹果 有关此文档

Do somebody know how to fix this issues? There's no Apple documentation about this

有.请始终阅读发行说明,在其中可以找到所有更改的摘要.然后重新检查文档,因为正如我所写的,您会发现Swift 1.2和Swift 2.0之间有许多重大变化.

There is. Always read release notes, where you can find summary of all changes. And then recheck documentation, because as I wrote, you can find many significant changes between Swift 1.2 and Swift 2.0.

这篇关于xCode 7 + Swift 2.0中的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆