How do you debug on breakpoints in swift on xcode? - xcode

I face trouble using po/p command in xcode using swift. It doesn't work always and gives error most of the time. Also its response is not useful most of the time. For example, when i type "po user" it gives instead of its details and items which i could expand while using objective-c
How do you debug any breakpoint? Are there any great external tools or alternatives available for this?

po command works in swift too
po yourvariable.description
po yourvariable.debugDescription
or
po print(yourvariable)

Having the same problem with Xcode 6 to 7.1.1. Here is a workaround until the gets bug fixed:
Use the p command instead. If this doesnt work then do "step into" before you type the p command.
p yourvariable.yourparameter
Reference this:
https://stackoverflow.com/a/28841849/4144106

Related

XCode lldb autocomplete

I have searched everywhere but can't seem to get answer. I am using Xcode 6.1.1.
I recall (possibly incorrectly) autocomplete being available in the lldb debug pane of XCode. I am currently typing fully all variables and functions; there must be a better way. Is autocomplete/intellisense available in Xcode?
Many Thanks.
The autocomplete available today in Xcode debugger console is for lldb commands. You can type fr<TAB> v<TAB> instead of frame variable. The autocomplete in lldb often can complete function names, for instance br s -n MyClass::MyMeth<TAB>. Or for a source file, br s -f myfil<TAB> -l 15. But once you're entering an expression (expr, or p, or po), the code completion you're used to seeing in the text editor panes is not available.

Swift code completion isn't working

I installed Xcode 6.0 beta and downloaded the iOS8 library Documentation.
but when i create a Swift project, try to typing code
func aa(){
let format = NSDateFormatter()
var pageData = format.
}
I find Xcode can't dot any property and function. Am I missing any step?
The problem is sloved, typing a whitespace can aid code completion
It's append when you change the hardware type and you choose less than iphone5.
Choose Iphone 6 for example in the list at the right of the stop button and the code completion for 'format' will appear.
I met the same problem and solve it by removing the non-ASCII char in comment (in my problem, it's a chinese char "年" automatically generated in comment by xcode).
btw. "typing a whitespace can aid code completion" doesn't work for me
It’s a bug, your code works on my system (OS X 10.9). Note that when typing code, I sometimes see the code completion crash for two seconds and come back.
When trying a first project named "swift", code completion crashed in a infinite loop… beta bugs… I just had to name it something else to test the language.
You know, I've experienced something similar with Objective C projects in Xcode 6 Beta 1. It seems Apple have changed the default behaviour a bit:
In Xcode 5.x code would always automatically complete as you type, but in this early beta try pressing ESCAPE - that will bring up the list you're looking for. Works for me. Some code auto completes as you type (both in Swift and Objective C), but at times only ESCAPE will bring up what we're looking for.
I'm nor sure if this is expected behaviour or a bug (I'm guessing the latter).
I must admit that your code works fine on my system without this trick. Just make sure you have code completion setup under Xcode - Preferences - Text Editing:

how to using NSZombieEnabled on intrument Xcode 3.2.5

i have some problem in memory management, and then i try to fix it using intrument tool.
Base on mark j video on you tube
about using NSZombieEnabled in intrument, i try to do like that. The problem is i never find a checkbox to set NSZombieEnabled active in my instrument. In this case i use xcode 3.2.5 and still on IOS 4.2.
This is the screenshot from the instrument that show no one check box for NSZombieEnabled activated :
am i doing something wrong??
help me please
thank you
Try running your application on simulator and see if you get the option in instruments. You may refer this tutorial to see how it is done in XCode 3.2 or you may refer the accepted answer in this thread for XCode 4.
Why not installing the new xCode 4? There you can easily set the EnvironmentVariables in the Scheme under the tab Arguments for Debug.
To check if it is actually set I use this code...
if(
getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled")
) {
NSLog(#"--------------------------------------->NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
}
There is a simple way to enable NSZombie if you are dealing with XCode version 4 through implementation of the following simple step:
Please click on the scheme drop down bar named Product choose -> edit scheme -> arguments tab and then add NSZombieEnabled in the Environment Variables column and YES in the value column...Now you are done with enabling NSZombie to find bugs in program.
When you run your app,you get an error message where the app crashes setting NSZombie state to enabled,but originally before enabling NSZombie,you might find it difficult to find out what's exactly wrong,like crash at autorelease pool,gdb break currently using objective-c,BAD_ACCESS errors etc... By enabling NSZombie you can find what is exactly the problem such as improper deallocation and trying to re-access,or improper release of memory etc..The errors may be of the following kind:
-[ExampleProgramViewController alertView:didDismissWithButtonIndex:]: message sent to deallocated instance 0x7068f70

XCode 4 Step into doesn't work

Im using XCode 4 and seeing a problem with debugging that did not exist in 3.x.
I am putting a breakpoint at a line where I call an object method.
Product *p = [[Product alloc] init];
[p print]; <-- Put a breakpoint here
After control stops at that line, I try to step into the method (F7). But nothing happens. System just skips over the line and goes to the next line (same behavior as Step Over).
Step into works fine for plain C language projects. The problem is with Objective-C methods. How do I fix this problem? Thanks.
Not sure if this will help -- Go into system preferences, and under the Keyboard general settings ensure that the "Use all F1 F2 etc. as standard function keys" option is checked.
F7 started to work for me after I checked that.
Hope that helps...
Check that the instance is not nil before trying to step into it's instance method. As embarrassing as it may seem, we all do it occasionally.
Stepping into ObjC method calls is not always possible. The way it was explained to me, there are internal runtime data structures that must be in a consistent state in order to reliably step into an ObjC method. If those internals happen to be in an inconsistent state when the program stops at your breakpoint, stepping in in the debugger will fail, and it will step over the call instead. This was also true in Xcode 3, and really has little or nothing to do with Xcode, but is an ObjC runtime and debugger issue. I estimate anecdotally (working in Xcode full-time for 3+ years) that stepping into an ObjC method call fails ~5% of the time. I find that it happens most often when it will be the most inconvenient to me. :)
That said, if you're NEVER able to step into ANY ObjC method call, then there's likely another problem, as I've been able to step into ObjC method calls many times with Xcode 4, and don't see this problem any more or less often than I did with Xcode 3.
fn+f7 always works for me. Although step into in Obj-C is kinda weird from time to time. You'd better set more breakpoints if you know where the code is heading.
I don't know enough about OSX to understand why this is fubar but I just tried changing the default key bindings to f13-f17 for all the usual bindings of pause/continue, step into/out of etc. Works for me. Pretty sucky QA on the XCode4 team possibly?
Switching to the gdb debugger works for me. Go to Edit Schemes, the Info tab for the Run phase, change from LLDB to GDB.
It's still not perfect. In particular it seems you have to use "Step into instruction" (with the appropriate key, or holding ctrl while hitting the step button) a lot if nothing happens, and to see registers and so on you have to use the gdb command line within the Xcode windows.
Remove the particular file and add the file again. This fixes my problem.

How to find source of print() or NSLog() console output in Xcode

I'm not sure if this is possible. Here is an example situation:
Something is printing to my console and I don't know where it is coming from in the code. I did a quick search using the Finder in Xcode on terms such as 'NSLog' and 'print'. Nothing relevant came up.
Is there any quick way that Xcode has of finding where the source of the output is coming from ?
Kind of like when you right click on a method and you have all the options of exploring different parts of the code associated with that method.
Also: are there other functions that print besides NSLog and print?
Thanks so much!
Try running in the debugger, with breakpoints set on printf, NSLog, etc. When you hit a breakpoint do a backtrace (bt) to see where it's being called from
There's a plugin LinkedLog for that. You replace all NSLogs with LLogs and then will be able to just tap on link in Xcode's console to get to the line caused it to appear.
Didn't try it myself, but definitely will.

Resources