Skip to content

Commit

Permalink
Converting snippets into new format with YAML front-matter
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Mar 29, 2015
1 parent 3a6258f commit 0ccd8cb
Show file tree
Hide file tree
Showing 31 changed files with 172 additions and 187 deletions.
13 changes: 6 additions & 7 deletions async.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// dispatch_async Pattern for Background Processing
// Dispatch to do work in the background, and then to the main queue with the results
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "dispatch_async Pattern for Background Processing"
summary: "Dispatch to do work in the background, and then to the main queue with the results"
completion-scope: Function or Method
---

dispatch_async(dispatch_get_global_queue(<#dispatch_queue_priority_t priority#>, <#unsigned long flags#>), ^(void) {
<#code#>

dispatch_async(dispatch_get_main_queue(), ^(void) {
<#code#>
});
Expand Down
11 changes: 5 additions & 6 deletions cdfetch.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Core Data Fetch
// Simple Core Data Fetch with Predicate & Sort Descriptor
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "Core Data Fetch"
summary: "Simple Core Data Fetch with Predicate & Sort Descriptor"
completion-scope: Function or Method
---

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:<#entityName#>];
fetchRequest.predicate = [NSPredicate predicateWithFormat:<#predicateFormat#>];
Expand Down
19 changes: 10 additions & 9 deletions checkerror.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// CheckError
// Function that extracts human-readable information from OSStatus codes.
// Credit: "Learning Core Audio: A Hands-on Guide to Audio Programming for Mac and iOS", by Chris Adamson, Kevin Avila
//
// Platform: All
// Language: C
// Completion Scope: Code Expression, Function or Method
---
title: "CheckError"
summary: "Function that extracts human-readable information from OSStatus codes."
credit: "'Learning Core Audio: A Hands-on Guide to Audio Programming for Mac and iOS', by Chris Adamson, Kevin Avila"
completion-scopes:
- Code Expression
- Function or Method
---

static void CheckError(OSStatus error, const char *operation) {
if (error == noErr) {
return;
}

char str[20];
*(UInt32 *) (str + 1) = CFSwapInt32HostToBig(error);
if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
Expand All @@ -19,7 +20,7 @@ static void CheckError(OSStatus error, const char *operation) {
} else {
sprintf(str, "%d", (int)error);
}

fprintf(stderr, "[Error] %s (%s)\n", operation, str);
exit(1);
}
11 changes: 5 additions & 6 deletions continuation.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Class Continuation
// Anonymous category to define private methods in an implementation
//
// Platform: All
// Language: Objective-C
// Completion Scope: Top Level
---
title: "Class Continuation"
summary: "Anonymous category to define private methods in an implementation"
completion-scope: Top Level
---

@interface <#Class Name#> ()
<#Continuation#>
Expand Down
12 changes: 6 additions & 6 deletions cvds.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// UICollectionViewDataSource
// Placeholders for essential UICollectionViewDataSource delegate methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "UICollectionViewDataSource"
summary: "Placeholders for essential UICollectionViewDataSource delegate methods"
platform: iOS
completion-scope: Class Implementation
---

#pragma mark - UICollectionViewDataSource

Expand Down
9 changes: 4 additions & 5 deletions documents.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Documents Directory Path
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "Documents Directory Path"
completion-scope: Function or Method
---

NSURL *documentsDirectoryURL = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
10 changes: 5 additions & 5 deletions frame.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Set Frame
// Initializes a view frame inside a code block
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "Set Frame"
summary: "Initializes a view frame inside a code block"
completion-scope: Function or Method
---

<# view #>.frame = ({
CGRect frame = <# view #>.frame;
Expand Down
12 changes: 6 additions & 6 deletions frc.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// NSFetchedResultsController
// Boilerplate for creating an NSFetchedResultsController
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "NSFetchedResultsController"
summary: "Boilerplate for creating an NSFetchedResultsController"
platform: iOS
completion-scope: Function or Method
---

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:<#(NSString *)#>];
fetchRequest.predicate = [NSPredicate predicateWithFormat:<#(NSString *), ...#>];
Expand Down
12 changes: 6 additions & 6 deletions frcd.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// NSFetchedResultsControllerDelegate
// Placeholders for the fetched results controller delegate methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "NSFetchedResultsControllerDelegate"
summary: "Placeholders for the fetched results controller delegate methods"
platform: iOS
completion-scope: Class Implementation
---

#pragma mark - NSFetchedResultsControllerDelegate

Expand Down
12 changes: 6 additions & 6 deletions imv.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ImageView
// Create & Initialize UIImageView with Named Image
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Code Expression
---
title: "ImageView"
summary: "Create & Initialize UIImageView with Named Image"
platform: iOS
completion-scope: Code Expression
---

[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"<#image name#>"]]
11 changes: 5 additions & 6 deletions init.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// init
// Designated incantation for your designated initializers
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "init"
summary: "Designated incantation for your designated initializers"
completion-scope: Function or Method
---

self = [super init];
if (!self) {
Expand Down
9 changes: 4 additions & 5 deletions library.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Library Directory Path
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "Library Directory Path"
completion-scope: Function or Method
---

[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
12 changes: 6 additions & 6 deletions lifecycle.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// UIViewController Lifecycle
// Placeholders for all of the view controller lifecycle methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "UIViewController Lifecycle"
summary: "Placeholders for all of the view controller lifecycle methods"
platform: iOS
completion-scope: Class Implementation
---

#pragma mark - UIViewController

Expand Down
12 changes: 6 additions & 6 deletions mailcomp.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// MFMailComposeViewController Initialization & Delegate
// Methods required to use the iOS Mail Composer
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "MFMailComposeViewController Initialization & Delegate"
summary: "Methods required to use the iOS Mail Composer"
platform: iOS
completion-scope: Class Implementation
---

#import <MessageUI/MessageUI.h>

Expand Down
14 changes: 8 additions & 6 deletions mark.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// #pragma Mark
// Dividers and labels to organize your code into sections
//
// Platform: All
// Language: Objective-C
// Completion Scopes: Top Level, Class Implementation, Class Interface Methods
---
title: "#pragma Mark"
summary: "Dividers and labels to organize your code into sections"
completion-scopes:
- Top Level
- Class Implementation
- Class Interface Methods
---

#pragma mark - <#Section#>
11 changes: 5 additions & 6 deletions nscoding.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// NSCoding Protocol Methods
// Placeholders for NSCoding protocol methods
//
// Platform: All
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "NSCoding Protocol Methods"
summary: "Placeholders for NSCoding protocol methods"
completion-scope: Class Implementation
---

#pragma mark - NSCoding

Expand Down
9 changes: 4 additions & 5 deletions nsl.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// NSLocalizedString
//
// Platform: All
// Language: Objective-C
// Completion Scope: Code Expression
---
title: "NSLocalizedString"
completion-scope: Code Expression
---

NSLocalizedString(@"<#Message#>", <#Comment#>)
11 changes: 5 additions & 6 deletions pdel.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// UIPickerViewDelegate
// Placeholders for required UIPickerView Delegate methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation
title: "UIPickerViewDelegate"
summary: "Placeholders for required UIPickerView Delegate methods"
platform: iOS
completion-scope: Class Implementation
---

#pragma mark - UIPickerViewDelegate

Expand Down
12 changes: 6 additions & 6 deletions pds.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// UIPickerViewDataSource
// Placeholders for required UIPickerView datasource methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "UIPickerViewDataSource"
summary: "Placeholders for required UIPickerView datasource methods"
platform: iOS
completion-scope: Class Implementation
---

#pragma mark - UIPickerDataSource

Expand Down
13 changes: 6 additions & 7 deletions singleton.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Shared Singleton
// Class method that returns a singleton instance
//
// Platform: All
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "Shared Singleton"
summary: "Class method that returns a singleton instance"
completion-scope: Class Implementation
---

+ (instancetype)shared<#name#> {
static <#class#> *_shared<#name#> = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_shared<#name#> = <#initializer#>;
});

return _shared<#name#>;
}
9 changes: 4 additions & 5 deletions stack.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Log Stack Trace
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "Log Stack Trace"
completion-scope: Function or Method
---

NSLog(@"Call Stack: %@", [NSThread callStackSymbols]);
11 changes: 5 additions & 6 deletions strongself.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// __strong self
// Declare strong reference to weak reference
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method
---
title: "__strong self"
summary: "Declare strong reference to weak reference"
completion-scope: Function or Method
---

__strong __typeof(<#weakSelf#>)strongSelf = <#weakSelf#>;
10 changes: 5 additions & 5 deletions tu.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// UIControlEventTouchUpInside
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Code Expression
---
title: "UIControlEventTouchUpInside"
platform: iOS
completion-scope: Code Expression
---

UIControlEventTouchUpInside
16 changes: 8 additions & 8 deletions tvdel.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// UITableViewDelegate
// Placeholders for required UITableViewDelegate protocol methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation
---
title: "UITableViewDelegate"
summary: "Placeholders for required UITableViewDelegate protocol methods"
platform: iOS
completion-scope: Class Implementation
---

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
<#statements#>
}
Loading

0 comments on commit 0ccd8cb

Please sign in to comment.