Debugging SQL with Core Data

Or select * from posts where info="useful"

Coming from WebObjects development, it was useful to be able to monitor the SQL being generated in order to see if what was really going on between the application and the database was even remotely similar to what I had intended. With Core Data development the option to see the SQL being generated is there, but I keep forgetting how to set it. Hence this post.

Setting executable arguments in Xcode

1In the Xcode project, select the actual application executable:

2From the toolbar, click on the Info icon

3In the Info window, click on the Arguments tab

4Add the following argument:

-com.apple.CoreData.SQLDebug 1

In order to save countless minutes wondering why nothing is being output to anything, remember that you only see the SQL output if the CoreData store is actually set to be of type NSSQLiteStoreType

In AppDelegate_m, persistentStoreCoordinator:

if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType...

Post your own comment here: