1.3 woud you please help a beginner from a small pit

I’m stacked at following part

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 (_:slight_smile: '?
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)
    
    
    
}

}

the save(name:) function should be below addName(_:slight_smile: function, not inside it.

So,

func save(name: String) {
    ...
}

should be below:

@IBAction func ついか(_ sender: UIBarButtonItem){

present(alert, animated: true)
}

In this situation, I think you can check out the “final” project included in the Supporting Materials

Hi Pantsz thank you for your reply

below, not inside,
so after ‘}’ of addName (){}

I’ll try it and report the result
see you later

Hello pantsz

I moved 'func save(name) ’ outside and below ‘func addName(ついか)’
and it works.

but new problem,it maybe the thing you expected

**Could not generate sources: The operation couldn’t be completed. (IDEFoundation.IDETemplateParseError error 1.) [0]

what did you see (or not find) in my code ?
What did you mean
*the “final” project included in the Supporting Materials
?

I appreciate your help with this situation.

Screenshot 2021-06-03 at 7.29.31 PM

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.

thank you pantsz, i found the ‘final’ !
now i have to search my error !
I’ll inform you the result.

thank you sooooooo much
hava a nice day !

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

Best,
Gina

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.

1 Like

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.

pantsz and Gina

thanks for you two, chapter 1 is done.
I keep going

see you

Hey, congratulations!

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.

can you recover your files afterwards?
if my files disappeared, I wouldn’t react so calmly, uh

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.

finally, i could clear that mission !

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

eh, I’m happy for you.
Thank you

This topic was automatically closed after 166 days. New replies are no longer allowed.