简体   繁体   中英

Cannot invoke 'functionName' with an argument list of type '([(nameOfClass)])' in Swift xcode 6.3.1

Im learning swift now and having the following problem Please help..

I have 3 classes- TableViewController BroadcastModel BroadcastRequest I get the following error (the line of error is marked with comment) Cannot invoke 'requestFinished' with an argument list of type '([(BroadcastModel)])'

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(...) {
... 
}
}

Since you are using:

 TableViewController.requestFinished(broadcasts)

You should define the function as a class function:

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

Recommend you to figure out the difference between function and class function and difference between class itself and class instance

If you want to do something to a class instance, you must have the reference to it, instead of only having the class name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM