Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. func traffikRoutes(){
  2. var url = createURLSandwich(filler: URLFiller.Route)
  3.  
  4. Alamofire.request(.GET, url, parameters: nil)
  5. .response { request, response, data, error in
  6.  
  7. if error != nil {
  8. println(error!.localizedDescription)
  9. return
  10. }
  11.  
  12. let json = JSONValue(data as? NSData)
  13.  
  14. if let routes = json["bustime-response"]["routes"].array {
  15. let realm = RLMRealm.defaultRealm()
  16. realm.beginWriteTransaction()
  17.  
  18. for val in routes {
  19. let route = Route()
  20.  
  21. if let rt = val[Route.kId].string {
  22. route.id = rt
  23. }
  24.  
  25. if let rtnm = val[Route.kName].string {
  26. route.name = rtnm
  27. }
  28.  
  29. if let rtclr = val[Route.kColor].string {
  30. route.color = rtclr
  31. }
  32.  
  33. let predicate = NSPredicate(format: "id = %@", route.id)
  34. // println("added new route \(route.name)")
  35.  
  36.  
  37. //ensure that no duplicates are stored
  38. if Route.objectsWithPredicate(predicate) == nil{
  39. realm.addObject(route)
  40. }
  41. }
  42.  
  43. println(Route.allObjects())
  44. realm.commitWriteTransaction()
  45.  
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement