How to Display Fetched Text in NSTextView

Hello:


I am trying to display some text in an NSTextView but thus far my efforts have been unsuccessful. Line 32, where I try to code to get the text to display causes a crash. the debug error message is: 2019-11-21 20:09:38.876811-0500 ScorcentMasterReview[49322:25437243] -[NSTextView documentView]: unrecognized selector sent to instance 0x101094620.


When I comment out line 32, the debug message is given below:


Any help would be appreciated.


Here is the code:

@IBActionfunc getQuestion(_ sender: Any) {
        func runConsistencyCheck() {
            do {
               
                try managedContext.save()
            } catch {
                print("An error occurred during consistency checking: \(error)")
            }
        }

           //      print ("Starting Fetch Function")
       guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else {
           
                        return
                }
              //     print ("Step Four")
        _ = appDelegate.persistentContainer.viewContext
            
        let fetchRequest = NSFetchRequest(entityName: "SCQ")
        fetchRequest.returnsObjectsAsFaults = false
       
          do {
                    items = try managedContext.fetch(fetchRequest)
                    print ("Record Returned is \(items)")
                } catch let error as NSError {
                    print("Could not fetch. \(error), \(error.userInfo)")
                }
            for item in items {
        if let record = item.value(forKey: "question") as? String {
                recordItem.append(record)
          let stringvalue = "questionText: \(recordItem)"
          questionView?.documentView?.insertText(stringvalue) //THIS LINE CAUSES A CRASH
                print(stringvalue)
                    }
        }
           for item in items {
        if let record = item.value(forKey: "distractor1") as? String {
                distractor1Item.append(record)
        let stringvalue = "distractor1Label: \(distractor1Item)"
                print(stringvalue)
                    }
        }
       
             for item in items {
            if let record = item.value(forKey: "distractor2") as? String {
                    distractor2Item.append(record)
            let stringvalue = "distractor2Label: \(distractor2Item)"
                    print(stringvalue)
                        }
            }
       
             for item in items {
            if let record = item.value(forKey: "distractor3") as? String {
                    distractor3Item.append(record)
            let stringvalue = "distractor3Label: \(distractor3Item)"
                    print(stringvalue)
                        }
            }
       
             for item in items {
            if let record = item.value(forKey: "distractor4") as? String {
                    distractor4Item.append(record)
            let stringvalue = "distractor4Label: \(distractor4Item)"
                    print(stringvalue)
                        }
            }
             for item in items {
            if let record = item.value(forKey: "distractor5") as? String {
                    distractor5Item.append(record)
            let stringvalue = "distractor5Label: \(distractor5Item)"
                    print(stringvalue)
                        }
            }

Here is the debug results when I comment out line 32 where I try to get the output:


questionText: (see figure) Using the maps; Which one of these was probably most recently settled?

distractor1Label: Iron Town

distractor2Label: Lake City

distractor3Label: Jonesville

distractor4Label: not here

distractor5Label: not here