title: Data is retrieved triple duplicately in a table view cells from SQlite in Swift ios
body: <p>I am retrieving the data from <code>SQLite</code> to a table view cells, but the data is being retrieved duplicate triple times, means on each data there should be a single cell in which the retrieved data will be. but the current situation is that for each data the three cells are being showed in a table view cell, how to retrieve data without duplication.</p>
  
  <p><a href="https://i.stack.imgur.com/kZsyh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZsyh.png" alt="enter image description here"></a></p>
  
  <p>Here is code :</p>
  
  <pre><code>import UIKit
  import SQLite
  import SQLite3
  
  @available(iOS 11.0, *)
  class ViewAssetViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
  
  var database: Connection!
  let assetsTable = Table("AssetTable")
  let assetid = Expression&lt;Int&gt;("assetid")
  let assetname = Expression&lt;String&gt;("assetname")
  let assetdescription = Expression&lt;String&gt;("assetdescription")
  let assetform = Expression&lt;String&gt;("assetform")
  let assetdate = Expression&lt;String&gt;("assetdate")
  
  
  var assetIdArray = [Int]()
  var assetNameArray = [String]()
  var assetDescArray = [String]()
  var assetTempArray = [String]()
  var assetCreateDateArray = [String]()
  
  var getAssetId = String()
  var assetIdIs = Int()
  var assetNameIs = String()
  var assetDescIs = String()
  var assetTempIs = String()
  var assetCreateDateIs = String()
  
  
      var SubmittedList = [String]()
  
      @IBOutlet weak var menu: UIBarButtonItem!
  
      @IBOutlet weak var SubmittedListTable: UITableView!
  
      @IBAction func SubmittedLeftAct(_ sender: Any) {
          print("submitted left action")
      }
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          self.getDataAssetIs()
          return assetNameArray.count
      }
      func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 1
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
          let cell = SubmittedListTable.dequeueReusableCell(withIdentifier: "SubmittedCell") as! SubmittedTableViewCell
  
       //   self.getDataAssetIs()
  
          cell.submittedLabel.text = assetNameArray[indexPath.row]
          cell.submittedOnLabel.text = "Created on: \(assetCreateDateArray[indexPath.row])"
          cell.associatedTempLabel.text = "Associated template: \(assetTempArray[indexPath.row])"
          cell.assetDescLabel.text = assetDescArray[indexPath.row]
  
          return cell
      }
  
  
      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return 150
      }
  
  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
      print("delete")
      if editingStyle == .delete {
          print("Deleted")
          let userId = assetIdArray[indexPath.row]
          let user = self.assetsTable.filter(self.assetid == userId)
          let deleteUser = user.delete()
          do {
              try self.database.run(deleteUser)
             // assetIdArray.remove(at: [indexPath.row])
              assetIdArray.remove(at: indexPath.row)
              assetNameArray.remove(at: indexPath.row)
              assetDescArray.remove(at: indexPath.row)
              assetTempArray.remove(at: indexPath.row)
              assetCreateDateArray.remove(at: indexPath.row)
  
              SubmittedListTable.deleteRows(at: [indexPath], with: .automatic)
  
            //  assetDescArray.remove(at: [indexPath.row])
  
              // numbers.removeAtIndex(indexPath.row)
              //tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
  
  
          } catch {
              print(error)
          }
      }
      SubmittedListTable.reloadData()
  }
  
  
  
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  
          // let indexPath = PDFListTable.indexPathForSelectedRow //optional, to get from any UIButton for example
  
          //  let currentCell = PDFListTable.cellForRow(at: indexPath!) as! PDFTableViewCell
          // formName = currentCell.titleLabel!.text!
          //    print(currentCell.titleLabel!.text!)
  
          self.moveToEdit()
  
      }
  
  
  func createAssetTable() {
      print("CREATE TAPPED")
      let createTable = self.assetsTable.create(ifNotExists: true){ (table) in
          table.column(self.assetid, primaryKey: true)
          table.column(self.assetname)
          table.column(self.assetdescription)
          table.column(self.assetform)
          table.column(self.assetdate)
          //try self.database?.run(usersTable.addColumn(formcreatedate))
      }
      do {
  
  
          try self.database?.run(createTable)
          print("Created Table")
      } catch {
          print(error)
      }
  }
  
  
  func getDataAssetIs() {
  
  
      do {
          let users = try self.database?.prepare(self.assetsTable)
          for user in users! {
              print("userId: \(user[self.assetid]), name: \(user[self.assetname]), email: \(user[self.assetdescription]), formcate: \(user[self.assetform]), mydate: \(user[self.assetdate])")
              assetIdIs = user[self.assetid]
              assetNameIs = user[self.assetname]
              assetDescIs = user[self.assetdescription]
              assetTempIs = user[self.assetform]
              assetCreateDateIs = user[self.assetdate]
  
              self.assetIdArray.append(assetIdIs)
              self.assetNameArray.append(assetNameIs)
              self.assetDescArray.append(assetDescIs)
              self.assetTempArray.append(assetTempIs)
              self.assetCreateDateArray.append(assetCreateDateIs)
  
  
              //print(formNameArray)
          }
      } catch {
          print(error)
      }
  
  }
  
  
  
  
  
  
      func moveToEdit() {
  
          let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle : nil)
          let desController = mainStoryBoard.instantiateViewController(withIdentifier: "ViewFormViewController") as! ViewFormViewController
          let newFrontViewController = UINavigationController.init(rootViewController:desController)
          revealViewController().pushFrontViewController(newFrontViewController, animated: true)
  
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          do {
              let documentDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
              let fileUrl = documentDirectory.appendingPathComponent("Stephencelis").appendingPathExtension("sqlite3")
              let database = try Connection(fileUrl.path)
              self.database = database
          } catch {
              print(error)
          }
  
          self.createAssetTable()
  
   /*
          if sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS AssetTable (assetid INTEGER PRIMARY KEY AUTOINCREMENT, assetname TEXT, assetdescription TEXT, assetform TEXT, assetdate Text)", nil, nil, nil) != SQLITE_OK {
              let errmsg = String(cString: sqlite3_errmsg(db)!)
              print("error creating table: \(errmsg)")
          }
  
     */
  
          SubmittedListTable.delegate = self
          SubmittedListTable.dataSource = self
  
          //SubmittedList = ["Asset title 1", "Asset title 2","Asset title 3","Asset title 4", "Asset title 5", "Asset title 6","Asset title 7", "Asset title 8", "Asset title 9","Asset title 10", "Asset title 11", "Asset title 12"]
          // Do any additional setup after loading the view.
  
  
          menu.target = revealViewController()
          menu.action = #selector(SWRevealViewController.revealToggle(_:))
          self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
  
          navigationController?.navigationBar.barTintColor = UIColor(red:0.00, green:0.52, blue:1.00, alpha:1.0)
          navigationController?.navigationBar.tintColor = UIColor.white
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
      }
  </code></pre>