Xcode 4和核心数据: 如何启用 SQL 调试

我正在开发一个通用的 iOS 应用程序,当我在调试时,我希望看到日志中的原始 SQL。有一些关于如何为 iOS 核心数据开发启用原始 SQL 日志的信息 在这篇博文里。给出的示例是 Xcode 3,我不清楚如何在 Xcode 4中启用它。

我尝试了“ Product”-> “ Edit Scheme”,并在“ Arguments Passed on Launch”中添加了“ - com.apple. CoreData.SQLDebug 1”,但是我仍然没有在日志中看到任何输出。不知道我是找错地方了还是只是传递参数不正确。

38371 次浏览

You should be looking at the same place you get NSLOGS

And you should Go to Product -> Edit Scheme -> Then from the left panel select Run YOURAPP.app and go to the main panel's Arguments Tab.

There you can add an Argument Passed On Launch.

You should add -com.apple.CoreData.SQLDebug 4 (number between 1 and 4, higher number makes it more verbose)

Press OK and your are all set.

The key here is to edit the scheme you will be using for testing.

XCode 4

It's in the same place I manage my NSZombieEnabled

Product -> Edit Scheme -> Run YouApp.app Debug

Under "Arguments Passed on Launch", paste in exactly:

-com.apple.CoreData.SQLDebug 1

Warning - this stuff is very verbose, if you're having Core Data issues, this might be well worth looking at, but it may also be more info than you need about the wrong thing.

I was having a problem with this and then realized it was a silly omission, which I assume is a comer mistake for some of you. When I entered the argument in Xcode (4.3.1), I left out the leading hyphen. I wouldn't have done so were I entering it on a command line, but in the GUI I had omitted it. I didn't find any difference between entering at 2 separate args or one (as some posts had suggested). So use:

-com.apple.CoreData.SQLDebug 1

and not simply:

com.apple.CoreData.SQLDebug 1

that worked for me in both simulator and real device

Note that you can put in different levels of the value passed. Which provide more and more verbosity.

-com.apple.CoreData.SQLDebug 1
-com.apple.CoreData.SQLDebug 2
-com.apple.CoreData.SQLDebug 3
-com.apple.CoreData.SQLDebug 4 // This will actually show parameter binds ("?")