如何在Swift 5中的Xcode Playground中创建Delegate设计模式?

问题描述 投票:0回答:1

我在使用Xcode Playground的时候遇到了一些问题。迅捷游乐场 并试图建立一个简单的 代表设计.

问题似乎是事实。协议不能被标记为公开Playground中的源文件夹被认为是一个新的模块。. 因此我找不到解决这个问题的方法。

以下是我目前的代码 (在源文件夹中,VIEWCONTROLLER在PLAYGROUND文件中)

//MARK: - Imports
import UIKit

//MARK: - Protocols
protocol UIManagerDelegate {
    func didChangePage(forward: Bool)
}

//MARK: - Properties & Initialisers
public class UIManager {

    // Properties
    private let parentView : UIView
    private var delegate: UIManagerDelegate

    // Initialisers
    public init(for view: UIView, delegate: UIManagerDelegate) {

        self.parentView = view
        self.delegate = delegate
    }
}

我得到的错误信息如下。Initializer不能被声明为public 因为它的参数使用了一个内部类型。 而当试图将协议标记为public时,也会产生错误。

你们有什么办法可以解决这个问题吗?"事先非常感谢你们的帮助。

ios swift xcode protocols swift-playground
1个回答
2
投票

使委托人公开

public protocol UIManagerDelegate
© www.soinside.com 2019 - 2024. All rights reserved.