Skip to content

Commit

Permalink
FIX: Data inconsistency
Browse files Browse the repository at this point in the history
Solved by droping database with every update
  • Loading branch information
syky27 committed Nov 23, 2016
1 parent 2b01de4 commit 15c07da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion LunchGuy/APIWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class APIWrapper {
}

func getRestaurants(completion: (error: NSError?)->()) {
do {
let realm = try Realm()
try realm.write({
realm.deleteAll()
})
}catch (let e) {
debugPrint(e)
}
Alamofire.request(Router.Restaurants)
.validate(statusCode: 200..<300)
.validate(contentType: ["application/json"])
Expand Down Expand Up @@ -105,11 +113,15 @@ class APIWrapper {
restaurant.restaurantID = json["data"]["attributes"]["title"].stringValue
realm.add(restaurant, update: true)

// It is wanted to delete all menus and replace them with new one as new day comes
// let allMenus = realm.objects(Menu)
// realm.delete(allMenus)

let menu = Menu()
menu.menuID = json["data"]["attributes"]["title"].stringValue
menu.cached = NSDate.dateFromISOString(json["data"]["attributes"]["cached"].stringValue)
realm.add(menu, update: true)
menu.meals.removeAll()


for content in json["data"]["attributes"]["content"].dictionaryValue {
for obj in json["data"]["attributes"]["content"][content.0].arrayValue {
Expand Down
1 change: 1 addition & 0 deletions LunchGuy/MenuTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class MenuTableViewController: UITableViewController {
cell.textLabel?.numberOfLines = 0
cell.textLabel?.frame = CGRectMake(cell.textLabel!.frame.origin.x, cell.textLabel!.frame.origin.y, 50, cell.textLabel!.frame.size.height);
cell.detailTextLabel?.text = "\(meal!.price)"
cell.detailTextLabel?.text = meal!.price < 1 ? "Cena není známa" : "\(meal!.price)"

return cell
}
Expand Down

0 comments on commit 15c07da

Please sign in to comment.