0
我正在嘗試遷移到swift 2.0,但並不是所有的代碼都能正常工作。我已經成功遷移了大部分代碼,但我仍然沒有使用EventKit的麻煩。下面的代碼在swift 1.2中工作正常。但現在我有一個問題Swift 2.0中的EventKit不能與Swift 2.0一起使用
import Foundation
import EventKit
import Cocoa
private let _SingletonSharedInstance = EventStore()
class EventStore {
let eventStore = EKEventStore()
class var sharedInstance : EventStore {
return _SingletonSharedInstance
}
init() {
var sema = dispatch_semaphore_create(0)
var hasAccess = false
eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: { (granted:Bool, error:NSError?) in hasAccess = granted; dispatch_semaphore_signal(sema) })
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER)
if (!hasAccess) {
println("ACCESS", "ACCESS LONG")
let sharedWorkspace = NSWorkspace.sharedWorkspace()
sharedWorkspace.openFile("/Applications/System Preferences.app")
exit (0)
}
}
}
行之後引起的問題
eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: { (granted:Bool, error:NSError?) in hasAccess = granted; dispatch_semaphore_signal(sema) })
我收到錯誤
不能援引「requestAccessToEntityType」與類型的參數列表「( EKEEntityType,完成:(Bool,NSError?) - >())'
我讀到使用NSError!
應該解決問題,但它沒有。 任何想法?
看到:http://stackoverflow.com/questions/31087340/compilation-errors-in-xcode-7-swift-2-0/33605707#33605707它的工作。 – ingconti