简体   繁体   English

无法从框架内访问公共枚举

[英]unable to access public enum from within a framework

I have been working on developing a framework and I have decided to create custom enums that extend the Error protocol to report to the host application when a domain specific error is encountered. 我一直在开发框架,我决定创建自定义枚举,扩展Error协议,以便在遇到域特定错误时向主机应用程序报告。

ie

public enum MyCustomError: Error {
    case customCase(message: String)
}

from the host application I have a response call back that is another enum with associated value 从主机应用程序我有一个响应回调,这是另一个具有相关值的枚举

ie

public enum MyCustomResponse {
    case success
    case error(Error)
}

form within the host application I try to access the error by doing the following 主机应用程序中的表单我尝试通过执行以下操作来访问错误

ie

let responseHandler: (MyCustomResponse) -> Void = { response in

    switch response {
        case .error(let error):
            if case let MyCustomModule.MyCustomError.customCase(theErrorMessage) = error {
                print(theErrorMessage)
            }
    }
}

what I am getting is a message from the compiler telling me that MyCustomModule has no member named MyCustomError . 我得到的是来自编译器的消息,告诉我MyCustomModule has no member named MyCustomError If a loose the MyCustomModule. 如果松散了MyCustomModule. then the compiler complains Use of unresolved identifier 'MyCustomError' . 然后编译器抱怨Use of unresolved identifier 'MyCustomError' I am importing MyCustomModule , and the access level of the MyCustomError is public , any ideas on how to solve this would be really appreciated. 我进口MyCustomModule和的访问级别MyCustomErrorpublic ,对如何解决这个任何想法将非常感激。

Thanks 谢谢

Note: I am developing my framework via cocoapods version 1.1.1 and using Xcode 8.2.1, swift version 3.0.2, supporting iOS version 8.0 and above. 注意:我正在通过cocoapods版本1.1.1开发我的框架并使用Xcode 8.2.1,swift版本3.0.2,支持iOS 8.0及更高版本。

Generated interface 生成的界面

import Foundation 

public enum MyCustomError : Error { 
    case customCase(message: String) 
}

After a long while trying out every little thing I could think of, even sandboxing the problem in a new repo (check github.com/anuragajwani/framework_pod_enums_test) without the ability to reproduce it I ended re-cloning the repository with the issue in question and reapplied all the changes and it worked no problem. 经过很长一段时间尝试,我能想到的每一件小事,甚至沙箱的问题在新的回购协议(检查github.com/anuragajwani/framework_pod_enums_test)没有重现它的能力,我最终重新克隆库与有关问题并重新应用所有更改,它没有问题。 Pitty I could not find the underlying problem, but by comparing each configuration setting in comparison with the sandboxed project and everything matching exactly I gave up. Pitty我找不到潜在的问题,但通过比较每个配置设置与沙盒项目的比较,以及完全符合我放弃的一切。 I have hunch that it had to with the compiler which given how flaky it is it would be no surprise. 我已经预感到它必须与编译器一起给出它有多么脆弱,这并不奇怪。

I had the exact same issue. 我有完全相同的问题。 In my case I just set the "Build Active Architecture Only" to "No" in the Build Settings and the issue was gone. 在我来说,我刚才设置的"Build Active Architecture Only" to "No"Build Settings和问题走了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM