2017-09-04 1 views
-1

Dieser Code:Erklärung Scope umfasst Klasse nicht in Swift

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) 
} 

gibt die Fehlermeldung "erwartete Erklärung" vor button.delegate = self.

Warum?

+1

-Code muss in Funktion sein. – rmaddy

Antwort

0

typischerweise

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

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

danke für die Hilfe :) –