Hello I have the following Code:
I want to display in the textView lines 53 and 54 below. If I don't include the Date (lines 49 - 51), the information displays. But if I include the display of the date nothing displays. I would like some help in understanding why and what to do to get the date information displayed.
@IBActionfunc showPerformance(_ sender: NSButton) {
studentsText.string = ""
groupNameItem = ""
// var event: String = ""
var convertedString: String = ""
var covertedTime: String = ""
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let newDateFormatter = DateFormatter()
newDateFormatter.dateFormat = "MM d"
let timeFormatter = DateFormatter()
timeFormatter.dateFormat = "HH-mm-ss"
let newTimeFormatter = DateFormatter()
newTimeFormatter.dateFormat = "h:mm a"
var groupNameItem = groupNameField.stringValue
guard (NSApplication.shared.delegate as? AppDelegate) != nil else {
return
}
_ = (NSApplication.shared.delegate as!
AppDelegate).persistentContainer.viewContext
_ = NSFetchRequest(entityName: "GroupRecord")
_ = NSSortDescriptor(key: "groupName", ascending: true)
let fetchRequest: NSFetchRequest = GroupRecord.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "groupName == %@ ", groupNameItem)
do {
let items = try managedObjectContext.fetch(fetchRequest)
groupNameItem = ""
for item in items {
if let record0Item = item.value(forKey: "grade") as? String
{
print ("Record 0 Item is \(record0Item)")
gradeItem.append(record0Item)
print ("Grade is \(gradeItem)")
if let record1Item = item.value(forKey: "groupName") as? String
{
print ("Record 1 Item is \(record1Item)")
groupNameItem.append(record1Item)
print ("Group Name is \(groupNameItem)")
if let record2Item = item.value(forKey: "score") as? String
{
print ("Record 2 Item is \(record2Item)")
groupScoreItem.append(record2Item)
print ("Group Score is \(groupScoreItem)")
if let record3Item = item.value(forKey: "date") as? String
{
dateItem.append(record3Item)
print ("Record 3 Item is \(record3Item)")
let newLine = ((dateItem) + (" ") + ("Grade") + (" ") + (gradeItem) + (" ") + (groupNameItem) + (" ") + ("Group Score") + (" ") + (groupScoreItem))
studentsText?.string = studentsText!.string + newLine + "\n"
groupNameItem = ""
groupScoreItem = ""
gradeItem = ""
}
}
}
}
}
print("\(items)")
print ("There are \(items.count) items")
print("Records are \(items)")
return()
} catch {
fatalError("Failed to fetch records: \(error)")
}
}