diff --git a/LunchGuy/APIWrapper.swift b/LunchGuy/APIWrapper.swift index dea2997..1af2136 100644 --- a/LunchGuy/APIWrapper.swift +++ b/LunchGuy/APIWrapper.swift @@ -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"]) @@ -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 { diff --git a/LunchGuy/MenuTableViewController.swift b/LunchGuy/MenuTableViewController.swift index 0a0c8cc..6c6a310 100644 --- a/LunchGuy/MenuTableViewController.swift +++ b/LunchGuy/MenuTableViewController.swift @@ -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) Kč" + cell.detailTextLabel?.text = meal!.price < 1 ? "Cena není známa" : "\(meal!.price) Kč" return cell }