我对 Swift 很陌生,我正试图以最好的方式将它连接到 UITableView。我决定使用 SwiftyJSON,这似乎很简单。我在 JSON 对象中的对象可能如下所示:
{
"id": "146",
"title": "Esports site Streak provides prize-heavy alternative to traditional betting",
"url": "http://www.dailydot.com/esports/streak-counter-strike-vulcun-betting/",
"image_url": "//cdn0.dailydot.com/cache/bb/cc/bbccc49d8271f2f3ed4c40b45c0fe0c0.jpg",
"date": "2015-04-10 22:07:00",
"news_text": "test teeeext",
"referer_img": "1"
}
到目前为止,我已经开始创建一个循环,该循环通过 viewDidLoad 中的所有循环创建循环
for (key: String, subJson: JSON) in jsonArray {
println(subJson)
}
之后我为所有新闻创建了一个类,如下所示:
class News {
var id: Int!
var title: NSString!
var link: NSString!
var imageLink: NSString!
var summary: NSString!
var date:NSString!
init(id: Int, title:NSString, link: NSString, imageLink:NSString, summary: NSString, date:NSString) {
self.id = id
self.title = title
self.link = link
self.imageLink = imageLink
self.summary = summary
self.date = date
}
}
但是我不确定这是否是创建它的最佳方法?我接下来的步骤是将它连接到 UITableView 吗?