Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift 4-如何在pods类中导入AppDelegate_Ios_Swift_Cocoapods - Fatal编程技术网

Ios Swift 4-如何在pods类中导入AppDelegate

Ios Swift 4-如何在pods类中导入AppDelegate,ios,swift,cocoapods,Ios,Swift,Cocoapods,我正在尝试将此代码添加到cocoapods库中的视图控制器 public override func viewWillDisappear(_ animated: Bool) { (UIApplication.shared.delegate as! AppDelegate).restrictRotation = .portrait } 但它使用了未声明的类型“AppDelegate”错误。。如何将AppDelegate之类的项目文件导入到Pod中?Pod应可在不同的项目中重用,因此您

我正在尝试将此代码添加到cocoapods库中的视图控制器

 public override func viewWillDisappear(_ animated: Bool) {
     (UIApplication.shared.delegate as! AppDelegate).restrictRotation = .portrait
}

但它使用了未声明的类型“AppDelegate”错误。。如何将AppDelegate之类的项目文件导入到Pod中?

Pod应可在不同的项目中重用,因此您不会在Pod中包含项目文件

通过让pod定义一个协议,然后由项目应用程序代表采用,您应该能够实现您的目标:

protocol RotationRestrictable {
    enum RotationRestriction {
        case .none
        case .portrait
        case .landscape
    }

    var restrictRotation: RotationRestriction
}
import YourPod

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RotationRestrictable {

    var restrictRotation: RotationRestrictable.RotationRestriction = .none {
        didSet {
           // Whatever you need to do
        }
    }
 ...
}
那么你可以说

public override func viewWillDisappear(_ animated: Bool) {
    if let delegate = UIApplication.shared.delegate as? RotationRestrictable {
        delegate.restrictRotation = .portrait
    }
}
在您的应用程序代理中:

protocol RotationRestrictable {
    enum RotationRestriction {
        case .none
        case .portrait
        case .landscape
    }

    var restrictRotation: RotationRestriction
}
import YourPod

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RotationRestrictable {

    var restrictRotation: RotationRestrictable.RotationRestriction = .none {
        didSet {
           // Whatever you need to do
        }
    }
 ...
}