Ios xCode 7+中的编译错误;Swift 2.0

Ios xCode 7+中的编译错误;Swift 2.0,ios,xcode,swift,swift2,xcode7-beta2,Ios,Xcode,Swift,Swift2,Xcode7 Beta2,由于我安装了xCode 7 beta2+Swift 2.0,我的应用程序中出现了一些错误。例如,我得到以下错误 无法使用类型为“(eEntityType,completion:(Bool,NSError!)->”的参数列表调用“requestAccessToEntityType” 在本部分代码中: eventStore.requestAccessToEntityType(EKEntityType.Event, completion: {(granted: Bool, error:NSEr

由于我安装了xCode 7 beta2+Swift 2.0,我的应用程序中出现了一些错误。例如,我得到以下错误

无法使用类型为“(eEntityType,completion:(Bool,NSError!)->”的参数列表调用“requestAccessToEntityType”

在本部分代码中:

eventStore.requestAccessToEntityType(EKEntityType.Event,
    completion: {(granted: Bool, error:NSError!) in
            if !granted {
                print("Access to store not granted")
            }
    })
calendarsPrueba.addObject(calendarWithName("US Holidays")!)
var predicate2 = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: calendarsPrueba as [AnyObject])
还有一个错误:

无法使用类型为“(NSDate,endDate:NSDate,calendars:[AnyObject])的参数列表调用“predicateForEventsWithStartDate”

在本部分代码中:

eventStore.requestAccessToEntityType(EKEntityType.Event,
    completion: {(granted: Bool, error:NSError!) in
            if !granted {
                print("Access to store not granted")
            }
    })
calendarsPrueba.addObject(calendarWithName("US Holidays")!)
var predicate2 = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: calendarsPrueba as [AnyObject])

有人知道如何解决这个问题吗?苹果公司没有关于这个问题的文档,就像@HAS一样-你运行了migrator吗?Swift 1.2和Swift 2.0之间有很多不兼容的更改。代码必须迁移或手动修复

请求访问实体类型

错误

无法使用参数列表调用'requestAccessToEntityType' 类型“(eEntityType,完成:(Bool,n错误!)->”

…之所以存在,是因为您的类型是
(Bool,NSError!)->Void
而不是
(Bool,NSError?->Void
。请将
NSError!
替换为
NSError?
以修复它

检查文件,签名为:

typealias EKEventStoreRequestAccessCompletionHandler = (Bool, NSError?) -> Void
func predicateForEventsWithStartDate(_ startDate: NSDate,
  endDate endDate: NSDate,
  calendars calendars: [EKCalendar]?) -> NSPredicate
谓词PreventSwithStartDate

无法使用参数列表调用“predicateForEventsWithStartDate” 类型为“(NSDate,endDate:NSDate,日历:[AnyObject])”

签名为:

typealias EKEventStoreRequestAccessCompletionHandler = (Bool, NSError?) -> Void
func predicateForEventsWithStartDate(_ startDate: NSDate,
  endDate endDate: NSDate,
  calendars calendars: [EKCalendar]?) -> NSPredicate
使用
作为[AnyObject]
时,您试图传递
[AnyObject]
而不是
[EKCalendar]
。若要解决此问题,请将
calendarsPrueba
声明为:

var calendarsPrueba: [EKCalendar]
并且不要将其强制转换为
[AnyObject]

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


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

这适用于Xcode 7/Swift 2:

final func addToCalendar(){

    let eventStore = EKEventStore()
    eventStore.requestAccessToEntityType(EKEntityType.Event, completion: { (granted, error) in
        if !granted {
            // Show alert...
            print("Access not allowed")
            print(error!.localizedDescription)
        }
        else {
            print("Access granted")
            let event = EKEvent(eventStore: eventStore)
            let uuid = NSUUID().UUIDString
            event.title = "sample Event " + uuid
            event.startDate = NSDate();
            event.endDate = event.startDate.dateByAddingTimeInterval(60*60)
            event.calendar = eventStore.defaultCalendarForNewEvents

            do {
                try eventStore.saveEvent(event,  span: .ThisEvent)
            } catch let error as NSError {
                print(error.localizedDescription)
            }
        }
    })

你运行迁移器了吗?