Group Group Group Group Group Group Group Group Group

Errata for Core Data by Tutorials v2.2

#1

This topic is for bugs, typos, and other mistakes in Core Data by Tutorials v2.2.

Chapter 2 unexpectedly found nil while unwrapping an Optional value
pinned #2
#3

Missing a “)” at the end of alert.addTextFieldWithConfigurationHandler statement on page 22.

#5

In chapter 6, the cell that has an image has no outlet set. This means that selecting the cell does nothing. Adding the outlet to the NoteDetailViewController and setting it to showNoteDetail gives the intended result of displaying the detail. There is however no UIImageView on that page either, not that this affects core data or the understanding of it, and as an advanced book users should know how to add one/use an if statement to determine whether or not to show the image, but it does leave a lacking feel to the end of the chapter. As this part of the project does not have anything to do with core data it would be nice to have it implemented as part of the starter project.

2 Likes
#6

Page 63. “NSQLiteStoreType” -> “NSSQLiteStoreType”

1 Like
#7

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.

#8

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

#9

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

#10

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.

#11

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 ! ?

#12

Neve mind I had typed = instead of :

var managedContext = NSManagedObjectContext
var managedContext: NSManagedObjectContext!

#13

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

#14

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

#16

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.

#17

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:

#18

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.

#19

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.

#20

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

#21

Thanks for finding that bhaze2263.

#22

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