宣言范围不包括Swift中的Class

时间:2017-09-04 05:38:10

标签: swift scope

此代码:

import UIKit
import CircleMenu

class ViewController: UIViewController {
    let button = CircleMenu(
        frame: CGRect(x: 200, y: 200, width: 50, height: 50),
        normalIcon:"icon_menu",
        selectedIcon:"icon_close",
        buttonsCount: 4,
        duration: 4,
        distance: 120)

    button.delegate = self
    button.layer.cornerRadius = button.frame.size.width / 2.0
    view.addSubview(button)
}

给出了错误"期望的声明"在button.delegate = self前面。

为什么?

1 个答案:

答案 0 :(得分:0)

典型地,

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        button.delegate = self
        button.layer.cornerRadius = button.frame.size.width / 2.0
        view.addSubview(button)
    }
}