我是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)
当我尝试编译代码时,我收到了错误Unresolved Identifier。我认为这是因为范围。任何人都可以指出正确的方向吗?谢谢!
答案 0 :(得分:1)
您的函数/方法,downloadData()
不会返回任何内容。
答案 1 :(得分:0)
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]()
}
}
只需实现downloadData方法即可。 编辑: 您可以使用EVReflection和Alamofire(Pods)下载json并创建Actors并填充数组。