Hello:
I have the following code: There are no build errors, But the first text field "groupName" saves immediately (even without pressing the enter key) when I move to the next field, before the rest of the fields are entered. Then saves again when I press the SAVE button. That does not happen with any of the other three fields.
Any help with identifying why that happesn will be appreciated.
import Cocoa
import CoreData
class GroupViewController: NSViewController {
var items: [NSManagedObject] = []
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var groupNameTextField: NSTextField!
@IBOutlet weak var memberOneTextField: NSTextField!
@IBOutlet weak var memberTwoTextField: NSTextField!
@IBOutlet weak var memberThreeTextField: NSTextField!
@IBAction func saveGroup(_ sender: Any) {
print("SAVE ACTION STARTED")
let appDelegate = NSApplication.shared.delegate as! AppDelegate
let managedContext = appDelegate.persistentContainer.viewContext
let registerStudentsObject = NSEntityDescription.insertNewObject(forEntityName: "PlayerGroups", into: managedContext)
print("MOC READ")
registerStudentsObject.setValue(groupNameTextField.stringValue, forKey: "groupName")
registerStudentsObject.setValue(memberOneTextField.stringValue, forKey: "name1")
registerStudentsObject.setValue(memberTwoTextField.stringValue, forKey: "name2")
registerStudentsObject.setValue(memberThreeTextField.stringValue, forKey: "name3")
print("FIELDS READ")
do
{
try managedContext.save()
items.append (registerStudentsObject)
print("groupName, name1, name2, name3 saved")
}
catch
{
print (error)
}
}
}
Here is the output log:
SAVE ACTION STARTED
CoreData: annotation: Connecting to sqlite database file at "/Users/wlionelwilliams/Library/Containers/AppDev.ScorcentMasterReview/Data/Library/Application Support/ScorcentMasterReview/ScorcentMasterReview.sqlite"
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'
CoreData: sql: pragma recursive_triggers=1
CoreData: sql: pragma journal_mode=wal
CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_MODELCACHE'
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'ACHANGE'
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'ATRANSACTIONSTRING'
MOC READ
FIELDS READ
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: SELECT Z_MAX FROM Z_PRIMARYKEY WHERE Z_ENT = ?
CoreData: annotation: getting max pk for entityID = 4
CoreData: sql: UPDATE OR FAIL Z_PRIMARYKEY SET Z_MAX = ? WHERE Z_ENT = ? AND Z_MAX = ?
CoreData: annotation: updating max pk for entityID = 4 with old = 26 and new = 27
CoreData: sql: pragma auto_vacuum
CoreData: annotation: sql execution time: 0.0000s
CoreData: sql: pragma auto_vacuum=2
CoreData: annotation: sql execution time: 0.0000s
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZPLAYERGROUPS(Z_PK, Z_ENT, Z_OPT, ZGROUPNAME, ZNAME1, ZNAME2, ZNAME3) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: details: SQLite bind[0] = (int64)27
CoreData: details: SQLite bind[1] = (int64)4
CoreData: details: SQLite bind[2] = (int64)1
CoreData: details: SQLite bind[3] = "SCORCENT"
CoreData: details: SQLite bind[4] = ""
CoreData: details: SQLite bind[5] = ""
CoreData: details: SQLite bind[6] = ""
CoreData: sql: COMMIT
CoreData: sql: pragma page_count
CoreData: annotation: sql execution time: 0.0000s
CoreData: sql: pragma freelist_count
CoreData: annotation: sql execution time: 0.0000s
groupName, name1, name2, name3 saved
SAVE ACTION STARTED
MOC READ
FIELDS READ
CoreData: sql: BEGIN EXCLUSIVE
CoreData: annotation: getting max pk for entityID = 4
CoreData: annotation: updating max pk for entityID = 4 with old = 27 and new = 28
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZPLAYERGROUPS(Z_PK, Z_ENT, Z_OPT, ZGROUPNAME, ZNAME1, ZNAME2, ZNAME3) VALUES(?, ?, ?, ?, ?, ?, ?)
CoreData: details: SQLite bind[0] = (int64)28
CoreData: details: SQLite bind[1] = (int64)4
CoreData: details: SQLite bind[2] = (int64)1
CoreData: details: SQLite bind[3] = "SCORCENT"
CoreData: details: SQLite bind[4] = "John Doe"
CoreData: details: SQLite bind[5] = "Jane Doe"
CoreData: details: SQLite bind[6] = "Peter Pan"
CoreData: sql: COMMIT
groupName, name1, name2, name3 saved