如何在 Swift 5 中的 Xcode Playground 中创建委托设计模式?
How to create the Delegate Design Pattern within an Xcode Playground in Swift 5?
我在使用 Swift Playground 并尝试设置一个简单的 Delegate Design 时遇到了某种问题.
The problem seems to be the fact, that protocols can not be marked as public but the source folder in a Playground is considered as a new Module. Therefore I can't find a solution for this problem.
这是我目前的代码(在源文件夹中,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
}
}
The error message I get is the following: Initializer cannot be declared public because its parameter uses an internal type. And when trying to mark the protocol as public, this also produces an error.
你们知道如何解决这个问题吗?
非常感谢您的提前帮助。
成为代表public
public protocol UIManagerDelegate
我在使用 Swift Playground 并尝试设置一个简单的 Delegate Design 时遇到了某种问题.
The problem seems to be the fact, that protocols can not be marked as public but the source folder in a Playground is considered as a new Module. Therefore I can't find a solution for this problem.
这是我目前的代码(在源文件夹中,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
}
}
The error message I get is the following: Initializer cannot be declared public because its parameter uses an internal type. And when trying to mark the protocol as public, this also produces an error.
你们知道如何解决这个问题吗? 非常感谢您的提前帮助。
成为代表public
public protocol UIManagerDelegate