无法在Swift xcode 6.3.1中使用类型'([(nameOfClass)])'的参数列表调用'functionName'

时间:2015-04-29 12:28:51

标签: ios arrays xcode swift

我现在快速学习并遇到以下问题 请帮忙..

我有3个班 - TableViewController BroadcastModel BroadcastRequest 我收到以下错误(错误行标有注释)  无法使用类型'([(BroadcastModel)])

的参数列表调用'requestFinished'
import UIKit

public class TableViewController: UITableViewController {

var broadcasts = [BroadcastModel]()
//MARK: ViewControllerLifecycle
override public func viewDidLoad() {

    super.viewDidLoad()
    //maybe will use the 2d array for sections of broadcasts..
    BroadcastRequest().requestNewBroadcasts()

}

public func requestFinished(requestedBroadcasts: [BroadcastModel]) {
    self.broadcasts = requestedBroadcasts  \* HERE IS THE ERROR *\
    self.tableView.reloadData()
}

public class BroadcastRequest {

func requestNewBroadcasts() {
    var broadcasts = [BroadcastModel]()
    .....
    .....
    broadcasts.append(broadcast)
    TableViewController.requestFinished(broadcasts)
}
}

public class BroadcastModel: NSObject, Printable {
let id: String
let broadcastURL: String
...
...
override public var description: String {
    return "ID: \(id), URL: \(broadcastURL) ....."
}

init(...) {
... 
}
}

1 个答案:

答案 0 :(得分:1)

因为您正在使用:

 TableViewController.requestFinished(broadcasts)

您应该将该函数定义为类函数:

class func requestFinished(requestedBroadcasts: [BroadcastModel]) {
    self.broadcasts = requestedBroadcasts  \* HERE IS THE ERROR *\
    self.tableView.reloadData()
}

建议您弄清楚函数和类函数之间的区别以及类本身和类实例之间的区别

如果要对类实例执行某些操作,则必须具有对它的引用,而不是仅具有类名。