title: how to update multiple records in core data using swift 3.0
body: <p>I have a json file through which I want to insert json variables into core data 
   - I have Parsed json
   - Called Insert function to save data 
   - called fetch function to display data </p>
  
  <ul>
  <li><p>to avoid repeated entries i applied delete query before parsing .</p>
  
  <ul>
  <li><p>but functionally it is wrong as every time view is loading all records are getting parsed and inserted .</p></li>
  <li><p>so that I want apply update query but dont know , how. </p></li>
  </ul></li>
  </ul>
  
  <p>below is my json file</p>
  
  <p><code>"Data": [
      {
        "NID": 9,
        "NoticeType": "General",
        "NoticeDetails": "Test notice to all school",
        "NoticeTitle": "Test notice to all school",
       },
      {
        "NID": 6,
        "NoticeType": "General",
        "NoticeDetails": "Notice to all school tset purpose",
        "NoticeTitle": "Notice to all school tset purpose",
         },
      {
        "NID": 5,
        "NoticeType": "General",
        "NoticeDetails": "Test to all school",
        "NoticeTitle": "Test to all school",
      },
      {
        "NID": 4,
        "NoticeType": "General",
        "NoticeDetails": "notice  to all test",
        "NoticeTitle": "notice  to all test",
      },
      {
        "NID": 3,
        "NoticeType": "General",
        "NoticeDetails": "Test notice for all",
        "NoticeTitle": "Test notice for all",
      }
    ]</code></p>
  
  <p>Below is my code for parsing, insertion and fetch Data</p>
  
  <pre><code>                    let responseJson = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String : AnyObject]
  
  
                      if let dataArray = responseJson?["Data"] as? NSArray
                      {
                          for i in 0..&lt;(dataArray as AnyObject).count
                          {
                              let jsonObjectInLoop = dataArray[i] as! [String : Any]
  
  
                              let NIDObject = jsonObjectInLoop["NID"] as! Int32
                              print("Print NID Object from json loop \(NIDObject)")
  
                              let noticeType = jsonObjectInLoop["NoticeType"] as! String
                              let noticeDetail = jsonObjectInLoop["NoticeDetails"] as! String
                              let noticeTitle = jsonObjectInLoop["NoticeTitle"] as! String
  
                              let naFileNameString = ""
  
                                  DatabseManager.sharedInstanceOfDatabase_Manager.insertNoticeFunc(nid_p: NIDObject , noticeType_p: noticeType , noticeDetails_p: noticeDetail , noticeTitle_p: noticeTitle)
  
  
  
                          }
  
                          self.fetchNotice()
                          DispatchQueue.main.async()
                          {
                                  //code
                                  self.DetailsTableView.reloadData()
                                  self.refreshControl.endRefreshing()
                          }
  
  
  
  
                      }
  
  
                  }
  ////
  
  func insertNoticeFunc(nid_p: Int32, noticeType_p: String, noticeDetails_p: String, noticeTitle_p: String)
      {
  
          //Insert Data
          let contextVar = appDelegateShared.persistentContainer.viewContext
          let noticeDetailContext = NoticeDetails(context: contextVar)
  
          noticeDetailContext.nid = nid_p
  
          noticeDetailContext.noticeType = noticeType_p
          noticeDetailContext.noticeDetails = noticeDetails_p
          noticeDetailContext.noticeTitle = noticeTitle_p
  
          appDelegateShared.saveContext()
  
      }
  
  
  
  /////
  
   func fetchNotice() -&gt; Void
      {
          let contextVar = appDelegateShared.persistentContainer.viewContext
  
          //Fetch Data
          do
          {
              let fetchCoreData = try contextVar.fetch(NoticeDetails.fetchRequest())
              let noticeResult = fetchCoreData as! [NoticeDetails]
  
              print("notice result count \(noticeResult.count)")
  
  
              for notice in noticeResult
              {
  
  
                  //Store Id's in NSUserDefault
                  UserDefaults.standard.set(notice.nid, forKey: "nID_key")
                  UserDefaults.standard.synchronize()
  
                  print("NID from Core data \(notice.nid)")
                  self.noticeIDArray.append(notice.nid)
  
                  self.dateArray.append(notice.noticeDate!)
                  self.noticeTitleArray.append(notice.noticeTitle!)
                  self.imageUrlArray.append(notice.imageUrl!)
                  self.noticeDescArray.append(notice.noticeDetails!)
                  self.postedByArray.append(notice.postedBy!)
  
              }
              //print("Date Array : \(self.dateArray)")
          }
          catch
          {
              print("Error in fetch notice")
          }
      }
  </code></pre>
  
  <p>I have searched a lot but i am not able to found proper solution .
  please provide any solution if possible </p>