Skip to content

Commit 7bbdfd6

Browse files
committed
Rewrite some code to use more pure Swift
1 parent 0aedb27 commit 7bbdfd6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

TableViewCellWithAutoLayout/TableViewController/Model.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import Foundation
99

1010
class Model
1111
{
12-
var dataArray: NSMutableArray = []
12+
var dataArray: Array<(title:String, body:String)> = Array()
1313

1414
func populate()
1515
{
1616
var fontFamilies = UIFont.familyNames()
17+
1718
for familyName: AnyObject in fontFamilies {
1819
if let familyNameString: String = familyName as? String {
19-
dataArray.addObject(["title": familyNameString, "body": randomLoremIpsum()])
20+
dataArray.append((title: familyNameString, body: randomLoremIpsum()))
2021
}
2122
}
2223
}
@@ -29,7 +30,7 @@ class Model
2930
let familyName: AnyObject = fontFamilies[r]
3031

3132
if let familyNameString: String = familyName as? String {
32-
dataArray.addObject(["title": familyNameString, "body": randomLoremIpsum()])
33+
dataArray.append((title: familyNameString, body: randomLoremIpsum()))
3334
}
3435
}
3536

TableViewCellWithAutoLayout/TableViewController/TableViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ class TableViewController : UITableViewController
104104

105105
// Configure the cell for this indexPath
106106
cell.updateFonts()
107-
let modelDictionary = model.dataArray[indexPath.row] as NSDictionary
108-
cell.titleLabel.text = modelDictionary.valueForKey("title") as String
109-
cell.bodyLabel.text = modelDictionary.valueForKey("body") as String
107+
let modelItem = model.dataArray[indexPath.row]
108+
cell.titleLabel.text = modelItem.title
109+
cell.bodyLabel.text = modelItem.body
110110

111111
// Make sure the constraints have been added to this cell, since it may have just been created from scratch
112112
cell.setNeedsUpdateConstraints()

0 commit comments

Comments
 (0)