Guest User

Untitled

a guest
Jun 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. {
  2. "categories": [{
  3. "name": "Default Category",
  4. "id": "default_category",
  5. "children": [{
  6. "uuid": "783f491fef5041438fb7a2c3bf6a3650",
  7. "name": "Accessories",
  8. "children": [{
  9. "uuid": "d21b4491ff784a9bae88de279b99fac3",
  10. "name": "All Accessories",
  11. "children": [{
  12. "uuid": "2b1a23c4107844ad8a7afc1b324d0ffd",
  13. "name": "Belts",
  14. "children": [{
  15. "uuid": "2b1a23c4107844ad8a7afc1b324d0ffd",
  16. "name": "Belts",
  17. "children": []
  18.  
  19. },
  20. {
  21. "uuid": "2b1a23c4107844ad8a7afc1b324d0ffd",
  22. "name": "Belts",
  23. "children": []
  24. }
  25. ]
  26. },
  27. {
  28. "uuid": "a1c2a64c36c2461cad3d5f850e4fd0f5",
  29. "name": "Hats",
  30. "children": []
  31. },
  32. {
  33. "uuid": "8f26bc764b8342feaa0cb7f3b96adcae",
  34. "name": "Scarves",
  35. "children": []
  36. },
  37. {
  38. "uuid": "aa1116d1a0254ecea836cc6b32eeb9e0",
  39. "name": "Sunglasses",
  40. "children": []
  41. },
  42. {
  43. "uuid": "9d7033233e8f47eaa69eb1aaf2e98cdd",
  44. "name": "Watches",
  45. "children": []
  46. }
  47. ]
  48. }]
  49. }],
  50. "uuid": "6a23415771064e7aaad59f84f8113561"
  51. }]
  52. }
  53.  
  54. for currentCategory in mainCategories {
  55.  
  56.  
  57. guard against if there are child categories
  58. guard var children = currentCategory.children, children.count > 0 else {
  59. // Save the context
  60. self.coreData.saveStore()
  61. continue
  62. }
  63. for thisChildCategory in children {
  64.  
  65. if thisChildCategory.children?.count > 0 {
  66. for innerChildCategory in thisChildCategory.children! {
  67. print("innerChildCategory name (String(describing: innerChildCategory.name))")
  68. }
  69. }
  70.  
  71. if let child = thisChildCategory.children {
  72. children = child
  73. }
  74.  
  75. // Create new object
  76. if let currentChildCategory = self.coreData.insertNewObject(CoreDataEntities.BijouCategories.rawValue,
  77. keyValues: ["id" : thisChildCategory.id! as Optional<AnyObject>,
  78. "uuid" : thisChildCategory.uuid as Optional<AnyObject>,
  79. "name" : thisChildCategory.name! as Optional<AnyObject>,
  80. "gender" : thisChildCategory.gender as Optional<AnyObject>!,
  81. "active" : NSNumber(value: false)]) as? BijouCategories {
  82.  
  83. // Set as parent category
  84. currentChildCategory.parentCategory = parentCategory
  85.  
  86.  
  87. // Save the context
  88. self.coreData.saveStore()
  89.  
  90. }
  91. }
  92.  
  93. }
Add Comment
Please, Sign In to add comment