无法下标'[Post]'类型的值

时间:2015-12-19 13:40:50

标签: arrays swift

我不久前得到了这个错误,我不确定,错了什么。 Post只是普通的自定义类,有两个类型为String和初始化程序的属性。我的类有[Post]类型的属性,它基本上是Post类型的数组(我认为它与Array<Post>相同,但我不确定)。 我试图通过Post在特定索引处获得Int,但它不起作用。

这是发生异常的文件:

import UIKit

class NewsTableViewController: UITableViewController {
    var news = [Post]()

    override func viewDidLoad() {
        news = [Post(title: "Aplikace ITNetwork spuštěna.", author: User(name: "jan.ruzicka01", portfolio: "http://www.itnetwork.cz/portfolio/15392"))]
    }

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return news.count
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("carCell", forIndexPath: indexPath)

        cell.textLabel!.text = news[indexPath.row]

        return cell
    }
}

1 个答案:

答案 0 :(得分:0)

正如luk2302所提到的,实际错误是将'Post'类型的值赋值为'String'类型的值,但是编译器显示错误的错误,所以我很困惑。

相关问题