Errata for Core Data by Tutorials v2.2

Page 63. “NSQLiteStoreType” → “NSSQLiteStoreType”

1 Like

On page 54 “Build and run
”. Had an error with misspelled attribute. Corrected that now have console error “The model used to open the store is incompatible with the one used to create the store” Not sure how to proceed.

By the way I’m using “Bow Ties-Starter”, get the same console error with “Bow Ties-Final”.

Got a hint from “Compile Problem with Bowties Starter Project”. I reset the simulator and now it works fine!

As @drwhy already pointed out in a standalone topic: chapter 2 of the 2.2 e-book version is missing the save instructions in the insertSampleData() function on page 48, even though they are mentioned in the text on page 49.

I added

do { try managedContext.save() } catch let error as NSError { print("Save error: \(error), \(error.userInfo)") }

after the for loop that creates and inserts all the bowtie entities.

Chapter 2 Page 47
We’re instructed to type:
var managedContext: NSManagedObjectContext!

into ViewController.swift

I keep getting this error from Xcode:
Expected member name or constructor call after type name. Should it be parenthesis instead of the ! ?

Neve mind I had typed = instead of :

var managedContext = NSManagedObjectContext
var managedContext: NSManagedObjectContext!

Core Data by Tutorials v3.0

On page 45: I think it should be indicated to the reader which entity Codegen option should be set before generating the BowTie+CoreDataClass.swift and BowTie+CoreDataProperties.swift files. Using the default option results in Swift compiler errors during the build process.

Please see my response to this post for more details: Chapter 2: Error 'Bowtie' is ambiguous for type lookup in this context - #2 by harri

This mistake still exists in v3.0 of the book.

Here is an Error that still exists in version 3.1:

Chapter 1 - improvement for consistent use of data type

Page 20 declares the function argument datatype as UIBarButtonItem
@IBAction func addName(_ sender: UIBarButtonItem) { }

Page 22 defines the function argument datatype as AnyObject
// Implement the addName IBAction
@IBAction func addName(_ sender: AnyObject) { 
 }

Special thanks to @rogers for bringing this to our attention.

On page 189

fetchRequest.predicate = Predicate(format: “siteNumber == %@”, argumentArray: [siteNumber])

should be

fetchRequest.predicate = NSPredicate(format: “siteNumber == %@”, argumentArray: [siteNumber])

Special thanks to @operator and @tetanuss for bringing this to our attention. :slight_smile:

p. 31: (Not errata, rather clarification needed)
The book says:

[code here]

This is where Core Data kicks in! Here’s what the code does:

  1. Before you can save or retrieve anything from your Core Data store, you first need to get your hands on an NSManagedObjectContext. You can consider a managed object context as an in-memory “scratchpad” for working with managed objects.

However, nowhere in the example does the code specify the type NSManagedObjectContext. I’m sure a lot of beginners wouldn’t catch that with all the confusing names surrounding CoreData, and they would just gloss over the explanation of the code. But I wanted to actually understand the explanation, so I checked the Apple docs for NSManagedObjectContext, which was not very enlightening about where the Context might be used in the code.

My first impression of CoreData is: what kind of clusterf**k is this?! Did Apple really think this was a slick way to persist data?! Be that as it may, after looking around for 30 minutes or so, I started option+clicking on the variable names in Xcode, and it turns out that the variable managedContext has the type NSManagedObjectContext. So, I would suggest a rewrite like this:

[code here]

This is where Core Data kicks in! Here’s what the code does:

  1. Before you can save or retrieve anything from your Core Data store, you first need to get your hands on an NSManagedObjectContext, which is returned by appDelegate.persistentContainer.viewContext. You can consider a managed object context as an in-memory “scratchpad” for working with managed objects.

Yes, I know managedObject is a let variable, but calling let variables constants is confusing. If functional languages, whose variables cannot be changed, can call them variables, then so can Swift.

If you don’t want the text to get any longer, then delete the last line of the explanation–it means nothing to a beginner. If you want to keep the last line, then change it to something that a beginner has a chance of understanding, like:

A managed object context as like an in-memory array that holds managed objects.

I have no idea if that an accurate description, but at least it says something, rather than nothing. The term “scratchpad” is not a term of art in computer programming, and even if “scratchpad” were a term of art in computer programming, a beginner would not know what “scratchpad” means, so defining one unknown term with another unknown term does not serve to explain anything.

I did see that the docs use the term “scratchpad”, but copying nebulous descriptions from the docs does not serve to clarify the concept.

Next up, this explanation:

Think of saving a new managed object to Core Data as a two-step process: first, you insert a new managed object into a managed object context; then, after you’re happy with your shiny new managed object, you “commit” the changes in your managed object context to save it to disk.

It’s a good attempt to explain what’s going on in simple terms–and much appreciated. However, cracking a joke in the middle of the explantation serves to confuse rather than enlighten, so I would suggest the following change:

Think of saving a new managed object to Core Data as a two-step process: first, you insert a new managed object into a managed object context; then you set the properties of the managed object; then you “commit” the managed object context to save it to disk.

Well, I guess that’s a three step process.

In the chapter 2, for the rate(_ sender: Any) function in ViewController.swift, as the textField of the alert controller to rate a bow tie request a keyboard of type decimalPad, if the user has a keyboard with a coma for decimal numbers, the value won’t be converted to a Double in the update(rating: String?) function. The use of a NumberFormatter is necessary.

Not sure where is the errata page for v5.0, but page 98 has a missing “.” For count result type

Thanks for finding that bhaze2263.

Hello.
Core Data by Tutorials v5.0
In Chapter 1 page 15 was double writed a word “your”.
48

Hello here!
In chapter 2 “Chapter 2 NSManagedObject Subclasses” in section “Propagating a managed context” in source code
you convert UIImage into NSData by UIImagePNGRepresentation()

let imageName = btDict["imageName"] as? String
let image = UIImage(named: imageName!)
let photoData = UIImagePNGRepresentation(image!)!

Unfortunately UIImagePNGRepresentation is deprecated.

Use
let photoData = image!.pngData()!

Thank you for your work!

@nosov Thank you for the heads up - much appreciated! We will fix these in the next edition.

V5.0 seems to have lost the chapter links/ToC on the pdf version.

Thanks @linasses, we’re working to correct all of the editions released last year that are missing linked TOCs. I’ll update this thread when it’s been corrected and republished!