11

I'm working with Xcode 8 with swift on MacOS Sierra in an iOS app. I realized a few months ago that the SQLDebug stops working... (It used to worked in my app)...

I have created a new empty project with the coredata flag enabled..Then I created an entity with attributes and I executed this func in the ViewDidLoad and Xcode is NOT logging the 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{

    }
}
LPS
  • 581
  • 3
  • 8
  • 17

1 Answers1

19

Core Data uses the new unified logging framework starting with iOS 10. There is a known issue in Xcode that interferes with the logging, but you can use -com.apple.CoreData.Logging.stderr 1 to get around it.

EDIT: For clarity, you must specify -com.apple.CoreData.SQLDebug 1 in addition to the above. This actually enables the SQL trace, while the above will let you see it.

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

As part of this transition, Core Data honors user defaults to log to os_log, stderr, or both with ‘com.apple.CoreData.Logging.oslog’ or ‘com.apple.CoreData.Logging.stderr’. Due to a known issue in Xcode, it may be useful to toggle stderr logging on during debugging.

You might also look in the new Console app, which will display logs from devices connected to your Mac.

particleman
  • 635
  • 1
  • 7
  • 12
  • It's not working with that :( ... Im seeing a log like this: `2016-09-25 23:18:44.801810 GimApp[1940:69204] subsystem: com.apple.libsqlite3, category: logging, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0` – LPS Sep 26 '16 at 02:19
  • 2
    I just re-confirmed in my own project. Note that you still must have -com.apple.CoreData.SQLDebug 1 in the scheme, as stderr just enables the logging to be seen and SQLDebug enables the SQL trace. – particleman Sep 26 '16 at 14:37
  • Indeed, specifying both run-time options works. Perfect, thank you. – vilmoskörte Sep 26 '16 at 15:48
  • 1
    Thanks!! I had deleted the "SQLDebug" ...that was the problem... With both it's working :) – LPS Oct 01 '16 at 22:33
  • 1
    I have added -com.apple.CoreData.SyntaxColoredLogging YES in "Arguments Passed on Launch". But it didn't work for me. Can you guys help me? I have added com.apple.CoreData.SQLDebug & -com.apple.CoreData.Logging.stderr 1. I am able to see the core data log but I would like to see in different color – venky Oct 31 '16 at 13:12