How to set new line character programmatically for NSTableView

Hello I have the following piece of code to display data in NSTextView. I want to have a new line after each record. Need help to set the new line character so Swift will not concatenate each time a new record is inserted into the TextView, on line 28.

 

Any help will be appreciated.

 

{By the way, I’ve spent weeks trying to use the NSTableView without success. This method is simple and it gives me what I need).

 

 

 

 

@IBActionfunc showStudents(_ sender: NSButton) {

    guard (NSApplication.shared.delegate as? AppDelegate) != nil  else {
                       return
                   }
        _ = (NSApplication.shared.delegate as!
            AppDelegate).persistentContainer.viewContext
        _ = NSFetchRequest(entityName: "Registration")
        _ = NSSortDescriptor(key: "lastName", ascending: true)
                let fetchRequest: NSFetchRequest = Registration.fetchRequest()
            do {
                let items = try managedObjectContext.fetch(fetchRequest)
               for item in items {
                if let record0Item = item.value(forKey: "lastName") as? String
                  {
                  print ("Record Item is (record0Item)")
                 lastNameItem.append(record0Item)
                    print ("Last Name Item is (lastNameItem)")
                  if let record1Item = item.value(forKey: "firstName") as? String
                {
                    print ("Record Item is (record1Item)")
                firstNameItem.append(record1Item)
                    print ("First Name Item is (firstNameItem)")
                if let record2Item = item.value(forKey: "middleName") as? String
                {
                    print ("Record Item is (record2Item)")
                    middleNameItem.append(record2Item)
                    studentsText?.string = ((lastNameItem) + (" ") + (firstNameItem) + (" ") + (middleNameItem))
                    print ("Middle Name Item is (middleNameItem)")
                    }
                }
            }
         }
     }
}

Powered by WPeMatico

You may also like...

Comments are closed.