com.apple.CoreData.SQLDebug不起作用

我在iOS应用程序中使用MacOS Sierra上的Swift与Xcode 8一起工作。 我几个月前意识到SQLDebug停止工作…(它曾经在我的应用程序工作)…

我已经创build了一个新的空项目启用coredata标志..然后我创build了一个实体的属性,我在ViewDidLoad中执行此func和Xcode不logging的SQL

func fetchAllData(){ //1 delegate let appDelegate = UIApplication.shared.delegate as! AppDelegate let managedContext = appDelegate.persistentContainer.viewContext //2 prepare fetch request let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName:"Entrenamientos") //3 make fetch do{ let fetchedResults = try managedContext.fetch(fetchRequest) as! [NSManagedObject] } catch{ } } 

核心数据使用从iOS 10开始的新的统一日志logging框架。在Xcode中有一个已知问题干扰日志logging,但是您可以使用-com.apple.CoreData.Logging.stderr 1来绕过它。

编辑:为了清楚起见,除了上面的内容,你必须指定-com.apple.CoreData.SQLDebug 1。 这实际上启用了SQL跟踪,而上面会让你看到它。

https://developer.apple.com/library/content/releasenotes/General/WhatNewCoreData2016/ReleaseNotes.html

作为此转换的一部分,Core Data授予用户默认使用“com.apple.CoreData.Logging.oslog”或“com.apple.CoreData.Logging.stderr”login到os_log,stderr或两者。 由于Xcode中的已知问题,在debugging过程中切换stderrlogin可能会很有用。

您也可以查看新的控制台应用程序,该应用程序将显示连接到Mac的设备的日志。