相关疑难解决方法(0)

在super.init中引用self

我有以下代码(编辑:更新代码,以便每个人都可以编译并查看):

import UIKit

struct Action
{
    let text: String
    let handler: (() -> Void)?
}

class AlertView : UIView
{
    init(actions: [Action]) {
        super.init(frame: .zero)

        for action in actions {
//            let actionButton = ActionButton(type: .custom)
//            actionButton.title = action.title
//            actionButton.handler = action.handler
//            addSubview(actionButton)
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class TextAlertView : AlertView
{
    init() {
        super.init(actions: [
            Action(text: "No", handler: nil),
            Action(text: "Yes", handler: { [weak …
Run Code Online (Sandbox Code Playgroud)

closures initializer swift swift4

4
推荐指数
1
解决办法
761
查看次数

标签 统计

closures ×1

initializer ×1

swift ×1

swift4 ×1