Skip to content

Instantly share code, notes, and snippets.

@subdigital
Created January 5, 2013 21:59
Show Gist options
  • Star 42 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save subdigital/4463913 to your computer and use it in GitHub Desktop.
Save subdigital/4463913 to your computer and use it in GitHub Desktop.
What are your favorite Xcode Snippets? Add them in the comments.
// Property Nonatomic Strong
// Platform: All
// Completion Scopes: ClassInterfaceMethods
@property (nonatomic, strong) <# class_name #> *<# variable_name #>;
@jnjosh
Copy link

jnjosh commented Jan 5, 2013

Also, @mattt has a repo of several: https://github.com/mattt/Xcode-Snippets

@waynehartman
Copy link

UIWebViewDelegate

#pragma mark - UIWebViewDelegate

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    if (error.code != NSURLErrorCancelled) {

    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {

}

- (void)webViewDidStartLoad:(UIWebView *)webView {

}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    return YES;
}

@jasongregori
Copy link

weakself

__weak __typeof(self)weakself = self;

@gbasile
Copy link

gbasile commented Jan 7, 2013

These are some of the snippet I use with Dash, I normally use two empty spaces at the end of each snippet to avoid disambiguations

enum

typedef NS_ENUM(__type__, __name__) {
    @cursor
};

ifnotkind

if (!__variable__ || ![__variable__ isKindOfClass:[__class__ class]]) {
    @cursor
}

log

NSLog(@"@cursor");

errorDomain

#define __NAMEERRORDOMAIN__ @"__NAMEERRORDOMAIN__"
typedef NS_ENUM(__TYPEERRORDOMAIN__, __NAMEERRORCODE__) {
    __ERROR1__,
    __ERROR2__
};

s

@""

doc

//! __Description__
//! @param __param1Name__   __param1Description__
//! @return __returnDescription__   

safeselfblock

__block typeof(self) blockSafeSelf = self;

@aijaz
Copy link

aijaz commented Jan 11, 2013

These are great ideas. My favorite ones:

nss

NSString 

nsf

[NSString stringWithFormat:@"<#format#>", <#values#>]

nsl

NSLocalizedString(@"<#key#>", @"<#comment#>")

@djibouti33
Copy link

Quick log (qlog)

NSLog(@"<#message#>");

Log file and method name (method):

NSLog(@"%s", __PRETTY_FUNCTION__);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment