Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.apple.CoreData.SQLDebug not working

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{

    }
}
like image 278
LPS Avatar asked Sep 10 '16 23:09

LPS


People also ask

What is Core Data in iOS?

Overview. Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.

Should I use Core Data?

The next time you need to store data, you should have a better idea of your options. Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.

How can I view Core Data in iOS?

Open Xcode and create a new project by choosing the Single View App template form the iOS > Application section. Name the project Notes and check Use Core Data at the bottom. Open AppDelegate.

How do I set up NSManagedObject?

From the Xcode menu bar, choose Editor > Create NSManagedObject Subclass. Select your data model, then the appropriate entity, and choose where to save the files. Xcode places both a class and a properties file into your project.


1 Answers

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.

like image 120
particleman Avatar answered Oct 01 '22 12:10

particleman