Swift追加给出错过的参数错误

时间:2015-05-31 18:25:35

标签: ios swift uicolor

在将颜色UIColor添加到现有类之前,我的代码很好。添加颜色后:UIColor追加我的代码部分是错误(缺少','参数)。

我只粘贴了部分代码。请参阅底线以了解错误。

import Foundation
import UIKit



class DestinationType {

    var name: String                    // name of destination type
    var destinations : [Destination]    // all destinations in the type

    init (name:String, includeDestination:[Destination]) {
        self.name = name
        self.destinations = includeDestination
    }

    class func destinationTypes() -> [DestinationType] {
        return [self.summer(), self.winter()]
    }

    private class func summer() -> DestinationType {

        var destinations = [Destination]()

        destinations.append(Destination(name: "Antalya", description: "Very", imageName: "antalya.png", color: UIColor.greenColor) 

//预期','分隔符         }

如果需要,请在下面找到我的课程文件。

import Foundation
import UIKit

class Destination {

    var name : String
    var description : String
    var image : UIImage
    var color : UIColor

    init (name:String, description:String, imageName:String, color:UIColor) {
        self.name = name
        self.description = description
        if let img = UIImage(named: imageName) {
            image = img
        } 
        else {
            image = UIImage(named: "default")!
        }
        self.color = color
    }
}

2 个答案:

答案 0 :(得分:0)

destinations.append(Destination(name: "Antalya", description: "Very", imageName: "antalya.png", color: UIColor.greenColor) 

该行有两个(,只有一个)

答案 1 :(得分:0)

greenColor错过了括号。它必须是greenColor()

Swift的错误消息比给出错误的任何好的提示更具误导性: - (