我有一个应用程序,其应用程序结构如下。
- 申请
- FirstViewController
- 第二个 View Controller
- ABC框架
- ABCViewController
在我的ABCFramework中,我需要 FirstViewController 对象,但我无法在框架内导入或找到 FirstViewController。
最佳答案
该框架应该独立工作,而不应绑定(bind)到您当前的应用程序。
实现此目的的最佳方法是使用应用程序的委托(delegate)模式来响应框架触发的事件。下面是用户登录应用程序的示例
所以你可以这样做:
protocol ABCFrameworkProfileDelegate: AnyObject {
func userDidLogin()
func authenticationFailed(withError: Error)
}
然后在您的应用程序中:
import ABCFramework
// maybe on button tap?
let authService = ABCAuthService()
authService.login(username: "user", password: "pwd")
// once the login request completes either this or the failed method should be called.
func userDidLogin() {
let vc = FirstViewController()
push(vc, animated: true)
}
这样您的应用程序就可以根据发生的事件来管理要显示的 View 。
关于ios - 如何在框架中获取Viewcontroller引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58375946/