Possible typo in Saving TodoList section


#1

Either the following excerpt from the book contains a typo or I’m not understanding it correctly:

    func saveItems() {
        let itemsArray = items as NSArray

        print("Saving items to \(fileURL)")
        if !itemsArray.write(to: fileURL, atomically: true) {
            print("Could not save to-do list")
        }
    }

The saveItems() method first gets the URL using the function you just wrote. Next, you cast the items array into an NSArray.

This says that the saveItems() method first gets the URL. However, the code above does not access the fileURL property until after casting the items array into an NSArray.