我一直致力於開發框架,並決定創建自定義枚舉來擴展錯誤協議,以便在遇到特定於域的錯誤時向主機應用程序報告。無法從框架內訪問公共枚舉
即
public enum MyCustomError: Error {
case customCase(message: String)
}
從主機應用程序,我有一個響應回調是與相關值
即
public enum MyCustomResponse {
case success
case error(Error)
}
形式的主機應用程序,我嘗試訪問在另一個枚舉通過執行下列錯誤
即
let responseHandler: (MyCustomResponse) -> Void = { response in
switch response {
case .error(let error):
if case let MyCustomModule.MyCustomError.customCase(theErrorMessage) = error {
print(theErrorMessage)
}
}
}
我得到的是一條來自編譯器告訴我的消息MyCustomModule has no member named MyCustomError
。如果鬆動了MyCustomModule.
那麼編譯器會抱怨Use of unresolved identifier 'MyCustomError'
。我正在導入MyCustomModule
,並且MyCustomError
的訪問級別爲public
,關於如何解決這個問題的任何想法都將非常感激。
感謝
注:我通過的CocoaPods版本1.1.1
發展我的框架和使用的Xcode 8.2.1,快捷版本3.0.2,支持IOS版本8.0及以上。
生成的接口
import Foundation
public enum MyCustomError : Error {
case customCase(message: String)
}
你可以顯示什麼對象包含'public enum MyCustomError:Error'聲明? –
'MyCustomError'是上面指定的,我將其稱爲'MyCustomError.customCase(「MyCustomObject屬性A不能爲空」)。 @AshleyMills –
我的意思是,包含在另一個對象中的聲明,還是它在頂層? –