Using the Code Snippet Library from Xcode is very handy sometimes. However, the library consists only of a small amount of available code snippets. But you are not limited to them, rather than you can create your own code snippets for code patterns you are using very often.
Just follow these easy steps below to create your own snippet.
- Write your code snippet down at the code editor and select it.
- Be sure to open the code snippet library view within Xcode.
- Simply drag the selected code to the code snippet library.
- Enter a title and a short description of your snippet.
- Enter a shortcut for your snippet. You can choose any combination of letters but you should use something meaningful and you can remember easily.
- Choose a platform and the corresponding language the code snippet should be available in.
- The completion scope is also very handy to determine in which scopes (methods, class implementations, initializers, …) your code snippet should be available.
- The last step is to enter some placeholders within your code snippet. These placeholders will be shown as blue bubbles within your editor when using the code snippet and you can easily navigate to them by using your tab key. To create a placeholder just enter <#your_placeholder_name#>.
Creating a new UIViewController instance from a xib file and push it to the current navigation controller.
<#controller#> *controller = [[<#controller#> alloc] initWithNibName:@"<#controller#>" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:controller animated:YES]; [controller release];
Creating a new UIBarButtonItem and adding it to the current navigation item.
UIBarButtonItem *<#button#> = [[UIBarButtonItem alloc] initWithTitle:<#title#> style:UIBarButtonItemStylePlain target:self action:@selector(<#method#>)]; self.navigationItem.<#left_or_right#>BarButtonItem = <#button#>; [<#button#> release];
Leave a Reply