在Swift中更改backgroundColor,Xcode 6

我知道在iOS中更改backgroundColor的代码是这样的:

self.view.backgroundColor = UIColor.yellowColor() 

但由于某种原因,我收到“意外声明”错误。

有人知道为什么?

这是我正在处理的文件,ViewController.swift。 这实际上只是Xcode 6的一个新的单视图应用程序模板。

 // // ViewController.swift // backgroundColor // // Created by Frank Barrett on 11/21/14. // Copyright (c) 2014 Frank Barrett. All rights reserved. // import UIKit class ViewController: UIViewController { self.view.backgroundColor = UIColor.yellowColor() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 

错误是

/Users/frank/Dropbox/code/ios/backgroundColor/backgroundColor/ViewController.swift:13:5:预期?>声明

你把你的代码放在错误的地方。

 class ViewController: UIViewController { // This space is only for declarations. override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // Put this setup code in the viewDidLoad method. self.view.backgroundColor = UIColor.yellowColor() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }