-
-
Save subdigital/4463913 to your computer and use it in GitHub Desktop.
// Property Nonatomic Strong | |
// Platform: All | |
// Completion Scopes: ClassInterfaceMethods | |
@property (nonatomic, strong) <# class_name #> *<# variable_name #>; |
I just have this one listed with a shortcut of init
.
self = [super <#init function#>];
if (self == nil) return nil;
<#initializations#>
return self;
I also use tvds
to get a quick UITableViewDelegate
implementation
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier];
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return <# sections #>;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return <# cell_count #>;
}
Been using this a lot:
dispatch_queue_t workingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(workingQueue,
^{
// Heavy task
dispatch_async(dispatch_get_main_queue(),
^{
// Update UI
}
);
});
I actually have a whole series of those property snippets:
'pnc' - Copy Property
@Property (nonatomic, copy) <#Class name#> *<#Property Name#>;
'pns' - Strong Property
@Property (nonatomic, strong) <#Class name#> *<#Property Name#>;
'pnw' - Weak Property
@Property (nonatomic, weak) <#Class name#> *<#Property Name#>;
'pna' - Assign Property
@Property (nonatomic, assign) <#Type#> <#Property Name#>;
I also regularly use:
'mark' - create a pragma mark
pragma mark - <#Note#>
'todo' - A todo marked with my initials
// TODO (JNJ): <#Note#>
swf
[NSString stringWithFormat:@"<# format_string #>", <# args #>];
Also, @mattt has a repo of several: https://github.com/mattt/Xcode-Snippets
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;
}
weakself
__weak __typeof(self)weakself = self;
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;
These are great ideas. My favorite ones:
nss
NSString
nsf
[NSString stringWithFormat:@"<#format#>", <#values#>]
nsl
NSLocalizedString(@"<#key#>", @"<#comment#>")
Quick log (qlog)
NSLog(@"<#message#>");
Log file and method name (method):
NSLog(@"%s", __PRETTY_FUNCTION__);
Also useful is
propstring
:@property (nonatomic, copy) NSString *<# variable #>;