coreDataからレコード全体を削除しようとしています。私はデータを取り出し、それを操作用の配列に配置しました(このメソッドを使用してデータを編集できる別の関数があり、それはうまくいきます)。しかし、レコードを単に削除する方法はわかりません。 [.remove(at:index)]は動作せず、以下のコードもどちらも動作しません。私はすべてのフィールドを空にすることができますが、それは私が望むものではありません、私は完全にレコードが消えたい。 私はここでxCode 8/Swift 3&最新のコアデータ構文でコアデータからレコードを削除しようとしています
@IBAction func Delete(_ sender: UIButton) { // The delete function
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "DestinationsOne")
let context = appDelagate.persistentContainer.viewContext
var destArray = [DestinationsOne]() // The data array
do {
try destArray = context.fetch(request) as! [DestinationsOne]} //Fetching the data and placing it in the array
catch{
//error message
}
for index in (0..<destArray.count - 1){ //Go through the records
if destArray[index].destID == IDTitle!{ //Picks the record to edit
let object = destArray[index]
context.delete(object
} appDelagate.saveContext() }
私はまだこの質問でヘルプを使用できます。ありがとう –