Skip to content

Commit

Permalink
Example app elapsed time now prints out the non-optional form of the …
Browse files Browse the repository at this point in the history
…string.
  • Loading branch information
cnoon committed Jul 24, 2015
1 parent e0aa058 commit 0b14027
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Example/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class DetailViewController: UITableViewController {
var elapsedTime: NSTimeInterval?
var segueIdentifier: String?

static let numberFormatter: NSNumberFormatter = {
let formatter = NSNumberFormatter()
formatter.numberStyle = .DecimalStyle
return formatter
}()

// MARK: View Lifecycle

override func awakeFromNib() {
Expand Down Expand Up @@ -133,15 +139,14 @@ extension DetailViewController: UITableViewDataSource {
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
switch Sections(rawValue: indexPath.section)! {
case .Headers:
let cell = self.tableView.dequeueReusableCellWithIdentifier("Header") as! UITableViewCell
let field = self.headers.keys.array.sorted(<)[indexPath.row]
let value = self.headers[field]
cell.textLabel?.text = field
cell.detailTextLabel!.text = value
cell.detailTextLabel?.text = value
return cell
case .Body:
Expand Down Expand Up @@ -185,10 +190,8 @@ extension DetailViewController: UITableViewDelegate {
override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if Sections(rawValue: section) == .Body, let elapsedTime = self.elapsedTime {
let numberFormatter = NSNumberFormatter()
numberFormatter.numberStyle = .DecimalStyle
return "Elapsed Time: \(numberFormatter.stringFromNumber(elapsedTime)) sec"
let elapsedTimeText = DetailViewController.numberFormatter.stringFromNumber(elapsedTime) ?? "???"
return "Elapsed Time: \(elapsedTimeText) sec"
}
return ""
Expand Down

0 comments on commit 0b14027

Please sign in to comment.