我是 Swift 3 的新手,我对以下代码有问题:
func downloadData() {... downloads data about actors in JSON and initializes a Struct Actor}
然后:
class MasterViewController: UITableViewController {
var dataArray = [Actor]() //declare an empty array of type Actor
override func viewDidLoad() {
super.viewDidLoad()
dataArray = downloadData() //to populate an empty array with data downloaded from web
print(dataArray)
当我尝试编译代码时,我收到错误未解析的标识符。我认为这是因为范围。谁能指出我正确的方向?谢谢!
你的函数/方法,downloadData()
不返回任何内容。
class MasterViewController: UITableViewController {
var dataArray = [Actor]() //declare an empty array of type Actor
override func viewDidLoad() {
super.viewDidLoad()
dataArray = downloadData() //to populate an empty array with data downloaded from web
print(dataArray)
}
func downloadData() -> [Actor] {
return [Actor]()
}
}
只需实现下载数据方法。编辑:您可以使用EVReflection和Alamofire(Pods)下载json并创建Actor并填充数组。