我们如何在 Swift 中做类似前向声明的事情?
我在类之前声明了一个协议,但是协议需要使用在类之前声明的枚举(recordType):
protocol iCloudDelegate {
func errorUpdating(error: NSError)
func iCloudUpdated()
func iCloudFetched(recordType: recordType)
}
class iCloud {
enum recordType : String {
case Payment = "Payment"
case Subtype = "Subtype"
case Types = "Type"
case Entry = "Entry"
case Repeat = "Repeat"
}
}
现在 Swift 编译器抱怨Use of undeclared type 'recordType'错误。在 Objective-C 中,我们会放置某种前向声明,那么 Swift 呢?
作为一个附注问题,您看到上面我必须声明 case Types,而不是 Type,因为“Type”显然是枚举的保留 case-word。有什么办法可以克服这个吗?(当然,除了像我一样更改名称)