在 Xcode 中打开“Product -> Scheme -> Edit Scheme...”并添加到“Arguments Passed on Launch”:
-com.apple.CoreData.SQLDebug 3
-com.apple.CoreData.Logging.stderr 1
(iOS 10/macOS 10.12 或更高版本上的 Core Data 调试需要第二个启动参数,请参阅com.apple.CoreData.SQLDebug not working了解更多信息。)
您将看到 SQL 语句绑定到的所有值。示例输出:
test56[1588:c07] CoreData: sql: BEGIN EXCLUSIVE
test56[1588:c07] CoreData: sql: INSERT INTO ZEVENT(Z_PK, Z_ENT, Z_OPT, ZTIMESTAMP) VALUES(?, ?, ?, ?)
test56[1588:c07] CoreData: details: SQLite bind[0] = (int64)13
test56[1588:c07] CoreData: details: SQLite bind[1] = (int64)1
test56[1588:c07] CoreData: details: SQLite bind[2] = (int64)1
test56[1588:c07] CoreData: details: SQLite bind[3] = "368650709.435904"
test56[1588:c07] CoreData: sql: COMMIT