title: Delete UITableViewCell and synchronize with Plist
body: <p>i have a class as </p>
  
  <pre><code>class DropOffFrequentVC: UIViewController {
  
      @IBOutlet weak var tblView: UITableView!
  
      var googleDicCount : Int?
      var foursquareDicCount : Int?
      var favoriteGooglelocations  = [Int:GoogleItems]()
      var favoriteFourSquarelocations = [Int:FourSquareItems]()
  </code></pre>
  
  <p>i have a <code>UITableViewCell</code> as </p>
  
  <pre><code> func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
       .....
  
          if indexPath.section == 0 {
  
              cell.placeLbl.text = favoriteGooglelocations[indexPath.row]!.address
              cell.distanceLbl.text = favoriteGooglelocations[indexPath.row]!.distance
              cell.cityLbl.text =  favoriteGooglelocations[indexPath.row]!.name
              cell.favoriteBtn.tag = indexPath.row;
              cell.favoriteBtn.addTarget(self, action: "DeleteGoogleFavorite:", forControlEvents: UIControlEvents.TouchUpInside)
              cell.favoriteBtn.backgroundColor = UIColor.greenColor()
  
  
          } else if indexPath.section == 1 {
  
              cell.cityLbl.text = favoriteFourSquarelocations[indexPath.row]!.name
              cell.placeLbl.text = favoriteFourSquarelocations[indexPath.row]!.address
              cell.distanceLbl.text = favoriteFourSquarelocations[indexPath.row]!.distance
              cell.favoriteBtn.tag = indexPath.row;
              cell.favoriteBtn.addTarget(self, action: "DeleteFourSquareFavorite:", forControlEvents: UIControlEvents.TouchUpInside)
              cell.favoriteBtn.backgroundColor = UIColor.greenColor()
  
          }
  
          return cell
  
      }
  </code></pre>
  
  <p>On those favoriteBtn action i want to delete the cell and code for this is as</p>
  
  <pre><code> func DeleteGoogleFavorite(sender:UIButton){
  
    favoriteGooglelocations.removeValueForKey(sender.tag)
      let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
      let documentDirectory = paths[0] as! String
      let path = documentDirectory.stringByAppendingPathComponent("Favorites.plist")
      let succeed = NSKeyedArchiver.archiveRootObject(favoriteGooglelocations, toFile: path)
      println(succeed)
      loadFromPlist()
      self.tblView.deleteRowsAtIndexPaths([sender.tag], withRowAnimation:UITableViewRowAnimation.Automatic)
    }
  
  func DeleteFourSquareFavorite(sender:UIButton){
  
      favoriteFourSquarelocations.removeValueForKey(sender.tag)
      let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
      let documentDirectory = paths[0] as! String
      let path = documentDirectory.stringByAppendingPathComponent("FourSquareFavorites.plist")
      let succeed = NSKeyedArchiver.archiveRootObject(favoriteFourSquarelocations, toFile: path)
      println(succeed)
      loadFromPlist()
      self.tblView.deleteRowsAtIndexPaths([sender.tag], withRowAnimation:UITableViewRowAnimation.Automatic)
  
  
  }
  </code></pre>
  
  <p><em>May be i have problem on those above methods..I dont know how to delete the UITableViewCell and update the plist as required..How do i acheive this?And the rest of the code is as below</em></p>
  
  <pre><code>   func loadFromPlist(){
  
  
          let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
  
          let documentDirectory = paths[0] as! String
  
          let  googleFavouritepath = documentDirectory.stringByAppendingPathComponent("Favorites.plist")
  
          var googleDic = NSKeyedUnarchiver.unarchiveObjectWithFile(googleFavouritepath) as? [Int:GoogleItems]
  
          googleDicCount = googleDic?.count
  
          if(googleDic != nil){
              for (key,value) in googleDic!{
                  let item = value
  
                  println(item.name)
                  println(item.address)
  
                  var newLocation = GoogleItems()
                  newLocation.name = item.name
                  newLocation.address = item.address
                  newLocation.distance = item.distance
  
                  favoriteGooglelocations[key] = newLocation
                 // self.locations.append(newLocation)
  
              }
  
          }
  
          let  foursquareFavouritepath = documentDirectory.stringByAppendingPathComponent("FourSquareFavorites.plist")
          var fourSquareDic = NSKeyedUnarchiver.unarchiveObjectWithFile(foursquareFavouritepath) as? [Int:FourSquareItems]
          foursquareDicCount = fourSquareDic?.count
          if(fourSquareDic != nil){
              for (key,value) in fourSquareDic!{
                  let item = value
                  println(item.name)
                  println(item.address)
                  println(item.isStar)
  
                  var newLocation = FourSquareItems()
                  newLocation.name = item.name
                  newLocation.address = item.address
                  newLocation.distance = item.distance
                  favoriteFourSquarelocations[key] = newLocation
                  //self.foursquarelocations.append(newLocation)
  
              }
  
          }
  
      }
  </code></pre>
  
  <p>i Have the following error on the line as </p>
  
  <pre><code>func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int{
  
          if section == 0{
  
              if let temp = googleDicCount{
  
                  return googleDicCount! //this line gives me crash
  
              }else{
  
                  return 0
  
              }
  
          }else if section == 1{
              if let temp = foursquareDicCount{
  
                  return foursquareDicCount!
  
              }else{
  
                  return 0
  
              }
  
          }
  
          return 1
      }
  </code></pre>
  
  <blockquote>
    <p>GrabTaxi[603:9745] -[__NSCFNumber row]: unrecognized selector sent to
    instance 0xb000000000000003 2015-06-08 09:30:18.045 GrabTaxi[603:9745]
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber row]:
    unrecognized selector sent to instance 0xb000000000000003'</p>
  </blockquote>