I always have my Xcode assistant editor open with counterparts option. It's very handy to have an *.m file opened at standard editor while having corresponding *.h file in assistant editor.
After recent update to version 6.3 Xcode started to show random instead of corresponding headers quite often. Several clicks to "four squares" icon and mode usually brings it back (but it's very annoying).
Do you experience this too? How to fix it?
Note: deleting DerivedData didn't helped
As a workaround, one could use the Reset Editor command with the keyboard shortcut Command+Option+Shift+Z (US keyboard layout). If your keyboard layout doesn't match, you can see the key binding in View->Assistant Editor->Reset Editor. A word of caution, though, this will close any additional Assistant Editors you may have opened (the ones that open by clicking "+").
Another thing I noticed is the bug happens when you are switching Xcode windows or tabs but not when you are switching files within the same tab.
It looks like it's a just bug after all. I filed a bug report rdar://20684654. For a workaround see the accepted answer.
UPDATE: it's fixed in Xcode 6.4 beta
I have an app that is crashing with no error tracing. I can see part of what is going on if I debug, but can't figure out which object is "zombie-ing".
Does anybody know how to enable NSZombie in Xcode 4?
Environment variables are now part of the "scheme".
To edit the scheme and turn on zombies:
In the "Product" menu, select "Scheme" > "Edit Scheme...".
Go to the "Run Foo.app" stage in the left panel, and the "Arguments" tab on the right.
Add NSZombieEnabled to the "Environment Variables" section and set the value to YES, as you could in Xcode 3.
In Xcode 4.1 and above, there's also a checkbox on the "Diagnostics" tab of the "Run" stage to "Enable Zombie Objects".
With Xcode 6.4:
I encountered the same problem with troubleshooting EXC_BAD_ACCESS and had hard time to find the setting with Xcode 4.2 (the latest one that comes with iOS5 SDK). Apple keeps on moving things and the settings are no longer where they used to be.
Fortunately, I've found it and it works for the device, not just Simulator. You need to open the Product menu in the Xcode, select Edit scheme and then choose the Diagnostics tab. There you have "Enable Zombie Objects". Once selected and run in debugger will point you to the double released object! Enjoy!
In short
Product->Edit Scheme->Diagnostics-> Click Enable Zombie Objects
Product > Profile will launch Instruments and then you there should be a "Trace Template" named "Zombies". However this trace template is only available if the current build destination is the simulator - it will not be available if you have the destination set to your iOS device.
Also another thing to note is that there is no actual Zombies instrument in the instrument library. The zombies trace template actually consists of the Allocations instrument with the "Enable NSZombie detection" launch configuration set.
It's a simple matter of setting an environment variable on your executable (NSZombieEnabled = YES), and then running/debugging your app as normal.If you message a zombie, your app will crash/break to debugger and NSLog a message for you.
For more information, check out this CocoaDev page: http://www.cocoadev.com/index.pl?NSZombieEnabled
Also, this process will become much easier with the release of 10.6 and the next versions of Xcode and Instruments. Just saying'. =)
Product > Profile will pop up Instruments. Select zombies from the panel and go nuts.
Go to Product - Scheme - edit scheme - Arguments - Environment Variables set NSZombieEnabled = YES
In xcode 4.2
Goto, Product -> edit scheme -> click Run yourappname.app -> Diagonostics -> Enable Zombie object.
Here's a video and explaination how to use Instruments and NSZombie to find and fix memory crashes on iOS:
http://www.markj.net/iphone-memory-debug-nszombie/
As of Xcode 3.2.5 and Snow Leopard (Mac OS X 10.6), you can run your code through the Zombies instrument: Run > Run with Performance Tool > Zombies. That allows you to see particular objects and their retain counts on a timeline.
In Xcode 4.5.2 goto Product -> Edit Scheme -> and Under the Diagnostics tab check the check box in between Objective C and Enable Zombie Objects and Click on OK
To enable Zombie logging double-click the executable in the executables group of your Xcode project. At this point click the Arguments tab and in the Variables to be set in the environment: section, make a variable called NSZombieEnabled and set its value to YES.
In XCode 4.0: To detect NSZombie in Instruments, select the Simulator as your target (can't detect NSZomboe on device). Run Instruments (CMD+I) and select "Zombies" trace template. Enjoy.
In the preferences of your executable add the environment variable NSZombieEnabled and set the value to YES.
in ur XCODE (4.3) next the play button :) (run)
select : edit scheme
the scheme management window will open
click on the Arguments tab
you should see : 1- Arguments passed on launch
2- environment variables
inside the the (2- environment variables) place
Name: NSZombieEnabled
Value: YES
And its done....
NSZombieEnabled is used for Debugging BAD_ACCESS,
enable the NSZombiesEnabled environment variable from Xcode’s schemes sheet.
Click on Product⇒Edit Scheme to open the sheet and set the Enable Zombie Objects check box
this video will help you to see what i'm trying to say.
Is there anyway to format the code in Xcode like you can do in Eclipse or Netbenas. I have not found any option in menu, is there any hot key for this or its simply not in Xcode?
In Xcode 4, it's been moved to Editor > Structure > Re-Indent command (and has a default shortcut of CTRL+I ).
Select some text and then: Edit->Format->Re-Indent
You can bind this to a hotkey in the preferences.
Well, first of all welcome to 2021. I know it's a very old question but still people like me visit this and for those people, I'm putting out multiple available solutions in one answer that worked for me after 2 hours of research and testing.
Re-Indent
As everyone else is suggesting, it's one of the default solution if you just want to re-indent the lines of code:
Goto: Editor -> Structure -> Re-Indent or use shortcut control + I
Using Xcode Extensions
There are 2 extensions I found and used which works charmingly for me.
1) SwiftFormat: mentioning the steps to install the xcode extension here from the readme.
Like the command-line tool, you can install the SwiftFormat for Xcode
extension application via Homebrew. Assuming you already have Homebrew
installed, type:
$ brew install --cask swiftformat-for-xcode
open the SwiftFormat for Xcode.app that you just installed. there you can change the rules of formatting.
After that, open the system preference -> extensions -> xcode source editor and mark the checkbox for SwiftFormat.
Restart the Xcode
Voila! You're good to go. you can use three options. format selected code, format entire file OR just lint file.
2) Swimat: (it is already mentioned in one of the answer here by #Guy Daher) steps to install from readme
Install via homebrew-cask
Homebrew latest version
brew install --cask swimat
Similar to above extension installation, open the Swimat.app if it does not open then try to sove it from system preferences -> security & privacy -> open swimat app
after opening, click on install in ./bin folder to make it work globally (not sure about this step but I just did it)
Restart Xcode
now you can goto editor -> swimat -> format
Bingo! You're good to go.
Additional uninvited help
You can simply set the keybinding to use any of this command. i.e. I've set the android studio default command to reformat the code as option + command + L
ps If anyone else found a better extension, please let me know in comment, I'll add it to the list.
Other than re-indentation (Edit > Format > Re-Indent), not really. However, Xcode does have support for scripts (the menu to the right of the Window menu), so you could conceivably write a script that formats your code how you like it.
Edit: here are some links that touch on this subject:
http://hackertoys.com/2008/09/18/adding-a-code-beautifier-script-to-xcode (dead link)
http://8020world.com/jcmendez/2006/11/geeky-stuff/software/adding-a-script-menu-to-xcode-to-reformat-code-using-astyle (dead link)
Here are the shortcuts, to format the code in Xcode
1.Format entire code (entire class/controller)
select the entire code and press ⌘+| on mac to format your code.
2.Format particular block of code
select the code and press
⌘+] for right move and ⌘+[ for left move
Note : as per #JavierGiovannini sugesstion you can do using Editor Menu option
3.Select code --> Go to Editor --> Structure --> Re-Indent
My personal favorite code formatter is Uncrustify.
It has many, many options, so I also suggest you download UniversalIndentGUI, a GUI to help set Uncrustify's behavior to your liking.
XCode 8 Extensions
Another option is to use an extension like Swimat. Does the job for me. However, the caveat is that it does not format on save due to the restrictive Xcode Extension APIs, but they're trying to find a workaround.
Not saying this is best approach, but for completeness, if you cut and then paste the code back in, Xcode will automatically format it for you.
In v.4 you can make some adjustments through xCode preferences...
Fix code indentation in Xcode
^-I (control - capital i)
: format the current line
⌘-A + ^-I
: format the whole code file
Try this solution: ⌘A [⌘K ⌘F]
I have breakpoints set but Xcode appears to ignore them.
First of all, I agree 100% with the earlier folks that said turn OFF Load Symbols Lazily.
I have two more things to add.
(My first suggestion sounds obvious, but the first time someone suggested it to me, my reaction went along these lines: "come on, please, you really think I wouldn't know better...... oh.")
Make sure you haven't accidentally set "Active Build Configuration" to "Release."
Under "Targets" in the graphical tree display of your project, right click on your Target and do "Get Info." Look for a property named "Generate Debug Symbols" (or similar) and make sure this is CHECKED (aka ON). Also, you might try finding (also in Target >> Get Info) a property called "Debug Information Format" and setting it to "Dwarf with dsym file."
There are a number of other properties under Target >> Get Info that might affect you. Look for things like optimizing or compressing code and turn that stuff OFF (I assume you are working in a debug mode, so that this is not bad advice). Also, look for things like stripping symbols and make sure that is also OFF. For example, "Strip Linked Product" should be set to "No" for the Debug target.
In Xcode 7, what worked for me was:
Make sure that the Target > Scheme > Run - is in Debug mode (was Release)
Make sure to check the option "Debug executable":
Go to the Xcode Debugging preferences.
Make sure that "Load Symbols lazily" is NOT selected.
I was just having this same issue (again). After triple-checking "Load symbols lazily" and stripping and debug info generation flags, I did the following:
quit Xcode
open a terminal window and cd to the project directory
cd into the .xcodeproj directory
delete everything except the .pbxproj file (I had frank.mode1v3 and frank.pbxuser)
You can accomplish the same task in finder by right/option-clicking on the .xcodeproj bundle and picking "Show Package Contents".
When I restarted Xcode, all of my windows had reset to default positions, etc, but breakpoints worked!
One of the possible solutions for this could be ....go to Product>Scheme>Edit scheme>..Under Run>info>Executable
check "Debug executable".
For Xcode 4.x:
Goto Product>Debug Workflow and uncheck "Show Disassembly When Debugging".
For Xcode 5.x
Goto Debug>Debug Workflow and uncheck "Show Disassembly When Debugging".
Another reason
Set DeploymentPostprocessing to NO in BuildSettings - details here
In short -
Activating this setting indicates that binaries should be stripped and
file mode, owner, and group information should be set to standard
values. [DEPLOYMENT_POSTPROCESSING]
See this post: Breakpoints not working in Xcode?. You might be pushing "Run" instead of "Debug" in which case your program is not running with the help of gdb, in which case you cannot expect breakpoints to work!
Issue
Background
Xcode: 13.0
code: Objective-C
Issue: added breakpoint, but not work
(possible) Reason and Solution
Reason: Xcode bug
Solution: Product ->Clean Build Folder, then retry debug (multiple time)
Reason: disabled Debug
Solution: enable it: Product->Scheme->Edit Scheme->Run->Info
Build Configuration set to Debug
choose/select/enable: Debug executable
Reason: disabled all breakpoint
Solution: enable it: Debug panel -> click breakpoint icon
Reason: debug info be optimized
Solution: not optimize
click Project -> Build Settings -> Apple Clang - Code Generation -> Optimization Level -> Debug make sure is None[-O0]
Related
XCode's Symbolic breakpoint not work
Background
XCode crash log
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'
add XCode symbolic breakpoint
-[__NSCFConstantString stringByAppendingString:]:
but breakpoint not working
Solution
change to:
-[NSString stringByAppendingString:]
related doc: stringByAppendingString:
Solution for me with XCode 9.4.1 (did not stop at any breakpoint):
Under build Target -> Build Settings -> Optimization Level:
Switched from "Optimize for speed" -> "No optimization" (now it's slower but works)
What solved it in my case was quite simple, in Xcode - Product - Clean Build Folder followed by Product - Run (not the Play Xcode button).
(Had the issue on Xcode 11 -beta 4 after switching to unit testing with Xcode play button long press)
This had me in Xcode 9 for half a frustrating day. It ended up been a simple debug setting.
Go Debug > Debug Workflow and make sure 'Always Show Disassembly' is turned off. Simple as that. :(
Came to this page with the same problem (C code in Xcode 6 not stopping at breakpoints) and none of the solutions above worked (the project was practically out of the box, settings-wise, so little chance for any of the debugger settings to be set to the wrong value)...
After wasting quite some time reducing the problem, I finally figured out the culprit (for my code):
Xcode (/LLVM) does not like Bison-style #line preprocessor commands.
Removing them fixed the problem (debugger stopped at my breakpoints).
For Xcode 4:
go Product -> Debug -> Activate Breakpoints
This is applicable for all Xcode version. Shortcut key is: command key + Y. Press this key combination to activate/deactivate breakpoints.
I have a lot of problems with breakpoints in Xcode (2.4.1). I use a project that just contains other projects (like a Solution in Visual Studio). I find sometimes that breakpoints don't work at all unless there is at least one breakpoint set in the starting project (i.e. the one containing the entry point for my code). If the only breakpoints are in "lower level" projects, they just get ignored.
It also seems as if Xcode only handles breakpoint operations correctly if you act on the breakpoint when you're in the project that contains the source line the breakpoint's on.
If I try deleting or disabling breakpoints via another project, the action sometimes doesn't take effect, even though the debugger indicates that it has. So I will find myself breaking on disabled breakpoints, or on a (now invisible) breakpoint that I removed earlier.
I've had my breakpoints not work and then done Build / Clean All Targets to get them working again.
I think the problem could be incompatibility between device versions and Xcode. I have this problem when attempting to debug on my iPhone 4S running iOS 5.0.1. I am still using Xcode 3.2.5. I got the symbols from the handset by selecting "use this device for development" in the Organiser window. This phone refuses to breakpoint however. My old 3GS will breakpoint, same Xcode project, same settings... just different device and it's running iOS 4.0. I guess this is an Xcode bug in 3.2.5, since I have the symbols. Having tried all the solutions posted here so far, I have decided the solution to my problem is to go ahead and upgrade to XCode 4. Perhaps you cannot debug effectively unless your base SDK is at least as high as the system on which to debug. Maybe that's obvious - can anyone confirm?
Edit: I will update when I can confirm this is true.
Deleting my Build folder solved the problem for me.
If all else fails, instead of a breakpoint, you can call the following function:
void BreakPoint(void) {
int i=1;
#if !__OPTIMIZE__
printf("Code is waiting; hit pause to see.\n");
while(i);
#endif
}
To resume, manually set i to zero, then hit the resume button.
It has happened the same thing to me in XCode 6.3.1.
I managed to fix it by:
Going to View->Navigators->Show Debug Navigators
Right click in the project root -> Move Breakpoints (If selected the User option)
(I also Selected the option share breakpoints, even though I'm not sure if that necessary).
After doing that change I set the Move breakpoints options back to the project, and unselecting the Share breakpoints option, and still works.
I don't exactly know why but this get my breakpoints back.
For this, and also for Xcode 6 and above make sure that the breakpoint state button is activated (the blue arrow-like button):
In Xcode 4
- Product menu > Manage Schemes
- Select the scheme thats having debugging problems (if only one choose that)
- Click Edit button at bottom
- Edit Scheme dialog appears
- in left panel click on Run APPNAME.app
- on Right hand panel make sure youre on INFO tab
- look for drop down DEBUGGER:
- someone had set this to None
- set to LLDB if this is your preferred debugger
- can also change BUILD CONFIGURATION drop down to Debug
- but I have other targets set to AdHoc which debug fine once Debugger is set
I found the problem. Somehow the "Show Disassembly when debugging" was enabled in my XCode which creates that problem. When I disabled it, all my debugger stopped in my source code.
You can find it under: Product->Debug Workflow->Show Disassembly when debugging.
You can Activate / Disactivate Breakpoints in dropdown menu
I tried all the above things but for me only deactivating the debugging breakpoints once and then activating them worked.
When setting your break point, right click and you should get several options about how the break point is handled (log vars and continue, pause execution, etc)
Also make sure the "Load Symbols lazily" is not selected in the debug preferences.
(Applies to Xcode 3.1, not sure about past/future versions)
Also make sure that the AppStore distribution of the app is not also installed on the device.
Another thing to check is that if you have an "Entitlements" plist file for your debug mode (possibly because you're doing stuff with the Keychain), make sure that plist file has the "get-task-allow" = YES row. Without it, debugging and logging will be broken.
There appears to be 3 states for the breakpoints in Xcode. If you click on them they'll go through the different settings. Dark blue is enabled, grayed out is disabled and I've seen a pale blue sometimes that required me to click on the breakpoint again to get it to go to the dark blue color.
Other than this make sure that you're launching it with the debug command not the run command. You can do that by either hitting option + command + return, or the Go (debug) option from the run menu.
I have Xcode 3.2.3 SDK 4.1 Breakpoints will fail at random. I have found if you clean the build and use the touch command under build they work again.