2
我已經超載了一個名爲PBExcuse
類「==」運營商使用,但嘗試比較EKSourceType
對象時,編譯器試圖用我的PBExcuse
重載運營商,將無法編譯。錯誤消息是:「'EKSourceType'不能轉換爲'PBExcuse'」。斯威夫特:重載==操作符被另一種類型的
這裏是適用的代碼: 哪裏比較:
for (var i = 0; i < eventStore.sources().count; i++) {
let source:EKSource = eventStore.sources()[i] as EKSource
let currentSourceType:EKSourceType = source.sourceType
let sourceTypeLocal:EKSourceType = EKSourceTypeLocal
if (currentSourceType == sourceTypeLocal){ //something is wrong here!!
calendar.source = source;
println("calendar.source \(calendar.source)")
break;
}
}
在PBExcuse.swift:
func == (left:PBExcuse, right:PBExcuse) -> Bool{
if (left.event == right.event && left.title == right.title && left.message == right.message){
return true
}
return false
}
final class PBExcuse:NSObject, NSCoding, Equatable, Hashable{...}