1.3**** This takes the text in the text field and passes it over to a new method named save(name:) . Xcode complains because save(name:) doesn’t exist yet. Add the following implementation below addName(_:) :
I wrote codes as instructed but Xcode still complains for ‘save(name:)’
I’m not good at English,Where dose it mean exactly 'below 'addName (_ '?
I wrote them at wrong place ?
It worked well before this part
help me please
//
// ViewController.swift
// りすと
//
// Created by 押村宙枝 on 30/05/2021.
//
import UIKit
import CoreData
var people: [NSManagedObject] = []
class ViewController: UIViewController {
@IBOutlet weak var テーブル: UITableView!
var じけん: [String] = []
}
extension ViewController: UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
people.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let person = people[indexPath.row]
let cell = テーブル.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = person.value(forKeyPath: "name") as? String
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
title = "なにがあった?"
テーブル.register(UITableViewCell.self,forCellReuseIdentifier: "Cell")
}
@IBAction func ついか(_ sender: UIBarButtonItem){
func save(name: String) {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Person", in: managedContext)!
let person = NSManagedObject(entity: entity, insertInto: managedContext)
person.setValue(name, forKeyPath: "name")
do {
try managedContext.save()
people.append (person)
} catch let error as NSError {
print("ほぞんできません. \(error), \(error.userInfo)")
}
}
let alert = UIAlertController(title: "しんじじつ", message: "しんじじつついか", preferredStyle: .alert)
let saveAction = UIAlertAction(title: "ほぞん", style: .default){
[unowned self] action in
guard let textField = alert.textFields?.first,
let nameToSave = textField.text else {
return
}
self.save(name: nameToSave)
self.テーブル.reloadData()
}
let とりけし = UIAlertAction(title: "とりけし", style: .cancel)
alert.addTextField()
alert.addAction(saveAction)
alert.addAction(とりけし)
present(alert, animated: true)
}
In the book’s front page, click the “Download Supporting Materials” button, and you can find all the supporting materials divided by chapter, in each chapter’s folder, there is a “final” folder, which contains the “finished” project of that chapter. Comparing your code with that project may help when you have problems.
About the error, I am afraid I don’t know what cause it. In this situation, I will try to goggle the error message and hopefully find some information to solve it.
Hi and welcome to the forum community @dongri727! Looks like you were able to resolve your issue which is great. If you have further questions please don’t hesitate to ask here or feel free to join the official Ray Wenderlich Discord chat - Discord
Hi gdelarosa, thank you for your message.
I’m on a very first step of cording, i want to make DB for studying History.
So i started with this book, but i need some more basic study.
anyway thank you, i must ask you some help soon.
I think that my error caused the name of file.
I’m a Japanese and named projects with our own letters.
It seems not good for core data file so i’ve tried to rename it
but I failed and lost my files.
so I’ll rebuild it in english letters,it must be a good lesson for me.
If you are just starting coding, you may want to check out the Swift Apprentice book first, it teach you the programming language, then try UIKit Apprentice or SwiftUI Apprentice(pick one of it). I read UIKit Apprentice when I was a beginner, I remember it cover a bit of CoreData too.
I never read SwiftUI Apprentice, but I think it is like UIKit Apprentice but using newer framework to build UI, they are for beginner too.
For this Core Data book, I think if you finished chapter 4 or 5 and understand everything, you can probably handle the DB of a simple app already.
hi lisukovigor,
off course i wasn’t calm , i kicked the cat and the dog and everything
but it’s not job with appointed day of delivery
i’m studying so if i wrote them twice, i learned them better.
good lesson of coding also english for me.
moreover, chapter 1 is a short one.
I think that my error caused the name of file.
I’m a Japanese and named employee time tracking software projects with our own letters.
It seems not good for core data file so i’ve tried to rename it
but I failed and lost my files.
so I’ll rebuild it in english letters,it must be a good lesson for me