Saturday, June 29, 2024
HomeiOS Developmentios - Utilizing swipe to delete operate in swift on dictionary array

ios – Utilizing swipe to delete operate in swift on dictionary array

[ad_1]

I’m making an attempt to make use of the swipe to delete operate in Swift for my dictionary array and I carry on getting the error “Can’t convert worth of kind ‘Int’ to anticipated argument kind ‘Dictionary<String, String>.Index.” I’m not positive methods to change the info kind and methods to repair this.

That is my code:
import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
return time period.rely
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let phrases = Array(time period.keys)
    let that means = Array(time period.values)
    
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    cell.textLabel?.textual content = phrases[indexPath.row]
    cell.detailTextLabel?.textual content = that means[indexPath.row]
    return cell
}

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
   if editingStyle == .delete {
      time period.take away(at: indexPath.row)
      tableView.deleteRows(at: [indexPath], with: .fade)
   }
}

override func viewDidLoad() {
    tremendous.viewDidLoad()
    // Do any extra setup after loading the view.
    tblTerms.delegate = self
    tblTerms.dataSource = self
}
// Retailers
@IBOutlet weak var txtTerm: UITextField!
@IBOutlet weak var txtMeaning: UITextField!
@IBOutlet weak var tblTerms: UITableView!
@IBOutlet weak var lblCount: UILabel!
@IBOutlet weak var lblMessage: UILabel!

var time period: [String: String] = [:]

// Actions
@IBAction func btnAdd(_ sender: Any) {
    if txtTerm.textual content != "" && txtMeaning.textual content != "" {
    time period[String(txtTerm.text!)] = txtMeaning.textual content
    lblCount.textual content = String(time period.rely)
    tblTerms.reloadData()
    txtTerm.textual content = ""
    txtMeaning.textual content = ""
} else {
    lblMessage.textual content = "No time period or that means entered"
}

}
}

Cheers

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments