Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTangPL committed Oct 6, 2014
1 parent 748ef28 commit eb7cc54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let json = JSON(data:data)
viewController.json = json
} else {
viewController.json = JSON.Null(nil)
viewController.json = JSON.nullJSON
}

return true
Expand Down
26 changes: 12 additions & 14 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SwiftyJSON

class ViewController: UITableViewController {

var json: JSON = JSON.Null(nil)
var json: JSON = JSON.nullJSON

// MARK: - Table view data source

Expand All @@ -34,11 +34,9 @@ class ViewController: UITableViewController {
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch self.json {
case .Sequence(let array):
return array.count
case .Mapping(let dictionary):
return dictionary.count
switch self.json.type {
case Type.Array, Type.Dictionary:
return self.json.count
default:
return 1
}
Expand All @@ -49,12 +47,12 @@ class ViewController: UITableViewController {

var row = indexPath.row

switch self.json {
case .Sequence(let array):
switch self.json.type {
case .Array:
cell.textLabel?.text = "\(row)"
cell.detailTextLabel?.text = self.json.arrayValue.description
case .Mapping(let dictionary):
let key: AnyObject = (dictionary as NSDictionary).allKeys[row]
case .Dictionary:
let key: AnyObject = (self.json.object as NSDictionary).allKeys[row]
let value = self.json[key as String]
cell.textLabel?.text = "\(key)"
cell.detailTextLabel?.text = value.description
Expand All @@ -73,12 +71,12 @@ class ViewController: UITableViewController {

if let indexPath = self.tableView.indexPathForSelectedRow() {
var row = indexPath.row
var nextJson: JSON = JSON.Null(nil)
var nextJson: JSON = JSON.nullJSON

switch self.json {
case .Sequence:
switch self.json.type {
case .Array:
nextJson = self.json[row]
case .Mapping where row < self.json.dictionaryValue.count:
case .Dictionary where row < self.json.dictionaryValue.count:
let key = self.json.dictionaryValue.keys.array[row]
if let value = self.json.dictionary?[key] {
nextJson = value
Expand Down

0 comments on commit eb7cc54

Please sign in to comment.