Posts filed under Tips

14 Xcode Time Saving Keyboard Shortcuts - Memorize and Improve Your Productivity

Xcode 6 Keyboard Shortcuts

Update 9/25/14: Download the PDF version of the 14 Xcode keyboard shortcuts

Update 9/18/14: I added reader keyboard shortcut suggestions below (thanks!)

There are many keyboard shortcuts in Xcode 6 that can make yourself a more efficient programmer. They can help you quickly navigate around your code files to find and fix bugs, or to add new features to your apps.

When you’re in the zone, you want to be able to access the code files quickly, or the adjust Xcode’s panels to fit your small laptop screen.

The following keyboard shortcuts for Xcode 6 are the best ones to learn first. You will probably use them every day after you learn them.

Xcode Navigation Keyboard Shortcuts

1. Project Navigator: Command + 1

Quickly view all your code, images, and user interface files.

The Project Navigator is your central hub for all code, interface, and image files

The Project Navigator is your central hub for all code, interface, and image files

2. Show/Hide Navigator Panel: Command + 0

When you’re short on screen space, you’ll want to close anything that gets in the way. The happens a lot if you use the Assistant Editor (tuxedo) or when you design the user interface and connect it to code.

Show and hide the Navigator Panel

Show and hide the Navigator Panel

3. Show/Hide Utilities Panel: Command + Option + 0

The Utilities Panel is primarily used when you’re editing your user interface files. If you are only writing code, you can hide it.

 

Show and hide the Utilities Panel

Show and hide the Utilities Panel

4. Open file in Assistant Editor: Option + Left-click on file in Project Navigator

A quick way to open the Assistant Editor (Tuxedo button top right) is to Option click on a file you want to open side by side with the currently opened file.

Show multiple code or interface files with the Assistant Editor

Show multiple code or interface files with the Assistant Editor

Xcode Search Keyboard Shortcuts

When you are editing code, adding new code, or trying to fix a bug, searching is the fastest way to find something. Instead of scrolling through hundreds of lines of code you can find all occurrences of a variable, or jump to a specific line of text.

5. Find Navigator (ie. Search): Command + Shift + F

Find all the times you mentioned a variable or method name with the project search. You can match based on case, or ignore upper and lower case letters. 

You can also replace all occurrences of a variable name with a new variable name.

Search for text or symbols in your Xcode project

Search for text or symbols in your Xcode project

6. File Jump Bar: Control + 6 (Type the method/variable name + enter to jump)

Jump to a line of code within your current code file. If you have hundreds or thousands of lines of code, you can quickly narrow down where you need to insert code to support a new app feature.

Jump bar allows quick access to methods or variables within a code file

Jump bar allows quick access to methods or variables within a code file

7. Open Quickly: Command + Shift + O

If you prefer to only use the keyboard and not the mouse, you’re going to enjoy Open Quickly. It let’s you just type and jump to a method definition or a specific code file.

Open a file quickly or jump to specific method using Open Quickly

Open a file quickly or jump to specific method using Open Quickly

8. Jump Bar and Open Quickly Search Typing Shortcut

You can type the first letter of each word, which allows you to quickly switch to a file or find a particular line of code.

Example, in ViewController.Swift press Command + Shift + O and then type vDL. The first result will be the function with the name viewDidLoad()  

Type less and search more with using starting letters for method names: i.e. vDL for viewDidLoad

Type less and search more with using starting letters for method names: i.e. vDL for viewDidLoad

9. (Objective-C or C++) Switch between .h and .m files: Control + Command + Up Arrow

If you are writing Objective-C, C++, or using Open Source code written in either language, you might need to lookup existing code.

You can quickly switch between two related code files, like the header and implementation files in Objective-C using this Control + Command + Up Arrow shortcut.

If you’re writing code in Swift, you won’t need to worry about this shortcut, since Swift uses a single code file.

App Building and Cleanup

To try out your new app you have to run it, and occasionally Xcode doesn’t feel well, so you may have to clean it up.

These shortcuts will keep you writing code without stopping to use the mouse as much.

10. Run the app: Command + R

When I write code, I routinely use this command to make sure the app is running bug free. The more often you test your app the better, since you can find and fix bugs early, before they become big problems.

Run your first iPhone app - Press Play!

Run your first iPhone app - Press Play!

11. Clean the project: Command + Shift + K

Occasionally Xcode will freeze, or something in your app becomes unresponsive or unpredictable. When that happens you’ll first want to clean and then re-run the Xcode project.

If that still doesn’t fix the problem, close Xcode and re-open it again. 

Try to run the app, and if that doesn’t work, you need to see if there’s an error message that you can Google for more help.

You shouldn’t have to do this too often, since it’ll make building your app slower. It removes all the intermediary files and recreates them which takes more time to complete.

Clean up Xcode when it fails to work

Clean up Xcode when it fails to work

12. Build the app: Command + B

Checking to make sure the code you write is in working order is something you’ll want to do often.

Even though Xcode checks it shortly after writing, it can sometimes be delayed, or give false errors. Building your app project allows you to make sure it’s in working order before you go to code the next feature.

You don’t always have to run the app, if you are making minor changes, and that’s where building can help you do a quick check, so that you can get back to adding the next line of code.

Build your code to make sure you don't have any errors - quickly double check your work

Build your code to make sure you don't have any errors - quickly double check your work

Documentation and Help

Learning how to help yourself is equally important. If you haven't already taken a look at the Xcode documentation, use these shortcuts to lookup related code reference. 

Read or skim some of the reference guides to get better acquainted with the code that Apple provides, which you can use to make more robust iPhone apps.

13. Documentation and Reference: Command + Shift + 0 (Zero)

After you install all the documentation with Xcode, which it should do in the background after installing it. You can search the documentation offline, which is great when you’re traveling and you’re trying to figure out how to add a new screen or feature to your app.

Open the Documentation and Reference and search for a keyword that you’ve seen in code. You should be able to find some additional resources and sample projects through the Xcode documentation.

Find out how to use code with Documentation and reference guides

Find out how to use code with Documentation and reference guides

14. Quick Help: Option + Left-click on class or method name

Inline help can make it easier to learn what a class or piece of code is actually doing. There’s a lot of code that’s already written, which you can leverage with the help of Quick Help.

Hold Option and Left-click on a variable, class, or method name to get more details. You can quickly jump to the documentation, if you click on the reference link in the bottom of the popup.

Pro Tip: Jump directly to the reference guide by double-clicking the left mouse button while holding Option over a class name.

Get Quick Help to reference while you write code

Get Quick Help to reference while you write code

What Shortcuts do you use?

Share what hotkeys make you faster or more effective.

Reader Tips

One of my new favorites I learned just recently and use it often is Command + Shift + J, which reveals the file you currently have open in the project navigator. I spent my days in a very large codebase, so this is a very fast way to jump around.
— weendex
I’m a big fan of CTRL + 1 which opens the “Show Related Items” popup. If you have the cursor in any method and hit CTRL + 1 you can easily access all the callers and callees of the current method via this popup. I am constantly navigating up through the callers of a method to see how it’s used.
— skoll
Cmd + . to stop the iOS Simulator is generally pretty handy as well.
— weendex
One that isn’t in the article that I use all the time is Command + Option + Shift + Left-click a file. This presents you with a little popover and you can say where you want it opened in, an assistant editor, a tab, a window, etc.
— Cheezybob
Or if you really want to get serious about developing stuff get AppCode! http://www.jetbrains.com/objc/
— martinni39

Connect

Subscribe to start the Swift Primer course. Learn how to make your first iPhone app in Swift.

Complete Course Bundle - Swift iPhone App Courses

Signup for 4+ courses on making . Learn from daily lessons and code exercises with instructor support.



Posted on September 15, 2014 and filed under Tips .

Objective-C Syntax Highlighting with Squarespace 6 using SyntaxHighlighter without Developer Mode

Syntax Highlight for Objective-C on Squarespace 6

Update 6/19/14: This method works for Safari, but it keeps failing in Chrome. I've disabled it for now until I can investigate a better option. The code and method should still work, but the comparisons won't look different below.

I write a lot of code samples and I was using SyntaxHighlighter on my wordpress blog, but since I started using Squarespace I didn't have an easy solution to get it working. I spent the day digging around the internet and found some guides on how to get it to work without the Developer Mode on Squarespace. 

Syntax highlighting is useful because it makes it easier to digest what the different parts of a blog post are. You can easily separate the content from the code because of the coloring. I'll show a comparison with pros/cons and then you can jump to the guide to setup your Squarespace blog.

Code Sample Comparison for Squarespace Blogs

Code Paragraph Style

Here is a code sample without syntax highlighting using the "Code" paragraph style for the monospace font. It's rather buggy to get right in Squarespace 6. You copy paste into Squarespace and the formatting will be off (I have to delete every other newline (return)). Then I have to apply the "Code" tag and reformat again. It's super picky and if you modify the text too much you may have to reformat it.

Pros:

  1. Works out of the box
  2. Don't need to escape "<" characters with <

Cons

  1. Spacing is buggy
  2. Lots of text formatting
  3. Deleting text lines near, in, or around the Code paragraph style can alter the formatting

 

#import "ViewController.h"
@interface ViewController () <UIGestureRecognizerDelegate> {
CGFloat _centerX;
}
@end

@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];

UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftEdgeGesture:)];
leftEdgeGesture.edges = UIRectEdgeLeft;
leftEdgeGesture.delegate = self;
[self.view addGestureRecognizer:leftEdgeGesture];

// Store the center, so we can animate back to it after a slide
_centerX = self.view.bounds.size.width / 2;
}
@end

As you can see it becomes hard to read and really see the code. There is no syntax highlighting and controlling the spacing is manual. I'd have to manually fix each line to get it to indent properly, instead of defaulting to my copy/paste from my code editor.

SyntaxHighlighter Code Highlighting

Here is the same code sample with SyntaxHighlighter. Instead of doing a Text block, I use a Code block with HTML. To learn how to set it up, keep on reading below.

I'll use the

 installation method so that the code is inline with the blog, as opposed to the script method. The script method doesn't work well with RSS readers. Note: If you want your code indexed by Google, you'll want to use 

 to rank higher in search for the code.
                          

Pros

  1. Multiple programming languages supported via brushes.
  2. Respects code formatting/spacing

Cons

  1. Need to escape the < "less-than" characters as < (Find and replace all in the code block)
#import "ViewController.h"

@interface ViewController ()  {
    CGFloat _centerX;
}
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftEdgeGesture:)];
    leftEdgeGesture.edges = UIRectEdgeLeft;
    leftEdgeGesture.delegate = self;
    [self.view addGestureRecognizer:leftEdgeGesture];
    
    // Store the center, so we can animate back to it after a slide
    _centerX = self.view.bounds.size.width / 2;
}
@end

SyntaxHighlighter Makes Code Readable on your Blog

Now that you've seen the comparison, let's jump right in and set you up with SyntaxHighlighter on Squarespace 6. You don't need to upload files or enable developer mode to make it work. Instead we can link to already public javascript and css files.

1. Go to your Squarespace Settings Tab > Code Injection > Header

Settings > Code Injection > Header to add custom code to all pages hosted on  your Squarespace domain.

Settings > Code Injection > Header to add custom code to all pages hosted on  your Squarespace domain.

2. Add the following code to get syntax highlighting working for Objective-C, CSS, and javascript. I code in Objective-C, but I needed Javascript and CSS to show the code for this post.

 
 
 
 
 






  

 
 

3. Add a Code block for HTML code, and disable "Display Source". You'll have to hover the mouse on the left side of your "Edit Post" popup window with Squarespace 6. You'll see a "+" to add a new block.

Add a new block by hovering your mouse on the left side of Squarespace

Add a new block by hovering your mouse on the left side of Squarespace

4.  Scroll down in the popup until you find "Code" under the "More" section. Click it to add it. Or you can drag it to a specific position in the layout of your blog post on Squarespace 6.

Scroll down and look for the Code block under the More category.

Scroll down and look for the Code block under the More category.

5. Turn off the "Display Source" option and use the HTML code to have the code work properly.

Add your source code and make sure to replace any "<" characters with the < escape code for proper HTML formatting. If you don't, your source code won't render correctly and you'll see strange things on your blog page.

Disable the "Display Source" and make sure you are on HTML code. All < characters should be replaced with <

Disable the "Display Source" and make sure you are on HTML code. All < characters should be replaced with <

6. Add some sample code to display with syntax highlighting.

Sample code (Copy/Paste to your code block)

#import "ViewController.h"

@interface ViewController () {
    int _x;
}

@end

Output of Sample Code

#import "ViewController.h"

@interface ViewController () {
    int _x;
}

@end

Gotchas:

Code is Editable on Double-Click

The code uses a property to make it easy to copy/paste the full code block. If you want to disable this behavior you can add the code to disable quick-code. If you click off of the text area, it'll jump back to the code. It's a little annoying, but it can make it easier for your readers to copy/paste code from your website to their IDE.

#import "ViewController.h"

@interface ViewController () {
    int _x;
}

@end


How do I Remove Line Numbers?

Set the gutter to false after you set the brush. Include a ; (semicolon) to separate multiple arguments.

Source

#import "ViewController.h"

@interface ViewController () {
    int _x;
}

@end

Output

#import "ViewController.h"

@interface ViewController () {
    int _x;
}

@end

Xcode Copy and Paste Issue with Non-breaking Space Characters -  

Using the default script that I have linked has a bug where when you double click and copy, the code inserts non-breaking space character codes.   or  

To fix this, make sure in the code you placed under Code Injection in Squarespace's settings that you include an explicit white space character for your spaces. You can set this to any character you'd like. Normal spaces will fix the copy/paste issues.


SyntaxHighlighter Can't find brush for: js (etc)

Can't find brush for: js - We didn't uncomment or add the correct language brush for SyntaxHighlighter

Can't find brush for: js - We didn't uncomment or add the correct language brush for SyntaxHighlighter

You'll need to include a new script for each language that you want to support code formatting. I would only include the ones that you need.

You'll get this error dialog when a user loads the page and the brush type isn't supported. (Or if the source file original links you've used no longer exist)

Resources

Let me know if this post was helpful. I spent a lot of time trying to research it and figure out solutions to some of the common problems. You can take a look at the resources that I found helpful.

Connect

  1. Join my iPhone mailing list to keep learning about making iPhone apps.
  2. For more structured learning, signup for my online iPhone app course.
Posted on March 25, 2014 and filed under Programming, Tips .

Learning from Experience and Small Groups

When I first started learning iOS development it was hard. I had stumbling blocks all along the way and good reading materials were hard to find. The issues were so frequent that I started blogging about advanced topics to document what I learned. I fought with the old version of Xcode 3 and the learning curve of Xcode 4. Many things were changing (iOS 3.0, 4.0, 5.0, and 6.0), and the only way to remember how I fixed things was to write it down with pictures.

While my original blog is great for advanced topics it fails to help most beginners. That's why I started https://iPhoneDev.tv to connect and teach artists, designers, entrepreneurs, hobbyists, and tech enthusiasts.   

What's Changed?

There are a lot more resources today that make learning easier. Stackoverflow.com has more problems and solutions, Apples' World Wide Developer Conference (WWDC) gives  about the latest features on iPhone/iPad/iOS/Mac, and the have expanded and re-oriented themselves for .

Learning from Other Experiences

I think the most challenging thing I've learned has been how to rock climb, also known as bouldering. At RIT we have a rock climbing gym (Red Barn) and I never liked it until recently. 

Indoor bouldering has a set of climbing holds (hands/feet) that are in a "route" or path and marked by colored tape. The goal is to traverse the wall from start to finish to complete the route. Where I found frustration as a beginner was that I couldn't "visualize" how I would solve a path, nor could I complete more than a few steps along the way. I think I spent 2-3 months climbing 1-2 times a week and I didn't see improvement. I didn't even finish a full path for the first two months. So much failure ate away and demoralized me. I started each climbing session knowing that I wasn't going to get much further.

The solution I found was to climb with a beginner, because it allowed me to teach the very few things that I had learned to someone else. Teaching in itself is a learning process that re-enforces what we know. I think I became more aware of how I was holding my body, moving on the wall, and how to identify the mistakes with another beginner. It allowed me to see how I looked on the wall, with someone who wasn't great.

Good climbers show you how to do it right, but bad climbers highlight what you're doing wrong. I think the same thing can be applied to any other field of study.

Find a Beginner Programmer and Connect

A coach is just as important as the rest of the team. When you're working on iPhone app development by yourself it's easy to become frustrated and fail to figure out a bug. What you need is another beginner programmer who you can talk about the problems and teach what you've learned. Together you'll learn more than if you both worked in separate silos.

I think a coach is also good for those times that you hit a wall. As an advanced programmer I've seen a lot of the pitfalls and I've been there before. So I know how to get out, but you won't really learn if I give you all the answers. You'll become dependent on me solving your problems and not you solving your problems. As a coach I teach you good form, how to practice, and how to find the answers. 

As you practice and learn to program iPhone apps you need someone, a peer, that can speak the same language with you and not overwhelm your current knowledge level. It's important because they can become a source of motivation and a way to learn more effectively. You can teach them and they can teach you. In the end you'll learn more than you would from just reading a book.

Homework

  1. Find another beginner iPhone programmer or a small group of programmers. (Meetup.com, local iPhone group, or Skillshare group)
  2. Start reading 1-2 chapters a day of .
  3. Practice as you read about new topics. Keep Xcode open so that you can try and write code.
  4. Discuss your challenges and how you solved them with another beginner.

Posted on January 16, 2013 and filed under Tips .