Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Importing first batch of snippets from Xcode
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Nov 1, 2011
1 parent 6268f99 commit a599469
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
14 changes: 14 additions & 0 deletions async.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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

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

dispatch_async(dispatch_get_main_queue(), ^(void) {
<#code#>
});
});
10 changes: 10 additions & 0 deletions continuation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Class Continuation
// Anonymous category to define private methods in an implementation
//
// Platform: All
// Language: Objective-C
// Completion Scope: Top Level

@interface <#Class Name#> ()
<#Continuation#>
@end
15 changes: 15 additions & 0 deletions init.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// init
// Designated incantation for your designated initializers
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method

self = [super init];
if (!self) {
return nil;
}

<#initializations#>

return self;
11 changes: 11 additions & 0 deletions kvo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// KVO Setter
// Use when overriding @synthesized property setter methods
//
// Platform: All
// Language: Objective-C
// Completion Scope: Function or Method

[self willChangeValueForKey:@"<#ivar#>"];
[<#ivar#> autorelease];
<#ivar#> = [<#newValue#> retain];
[self didChangeValueForKey:@"<#ivar#>"];

This comment has been minimized.

Copy link
@nevyn

nevyn Dec 27, 2012

You shouldn't call will/did in a setter unless you have disabled automatic will/did using + (BOOL)automaticallyNotifiesObserversForKey:(NSString )key;. The KVO runtime will do that for you just based on the name of the method being "set".

This comment has been minimized.

Copy link
@mattt

mattt Dec 27, 2012

Author Contributor

Yes, of course. This was a snippet going back a while—perhaps before that was something the compiler did automatically. Either way, thanks for the reminder.

32 changes: 32 additions & 0 deletions lifecycle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// UIViewController Lifecycle
// Placeholders for all of the view controller lifecycle methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation

#pragma mark - UIViewController

- (void)viewDidLoad {
[super viewDidLoad];
}

- (void)viewDidUnload {
[super viewDidUnload];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
8 changes: 8 additions & 0 deletions mark.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// #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

#pragma mark - <#Section#>
16 changes: 16 additions & 0 deletions tvdel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// UITableViewDelegate
// Placeholders for the core table view delegate methods
//
// Platform: iOS
// Language: Objective-C
// Completion Scope: Class Implementation

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case <#constant#>:
<#statements#>
break;
}
}
33 changes: 33 additions & 0 deletions tvds.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// UITableViewDataSource
// Placeholders for the core table view data source methods
//
// Platform: All
// Language: iOS
// Completion Scope: Class Implementation

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return <# number #>;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case <#constant#>:
<#statements#>
break;
default:
return 0;
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:<#(UITableViewCellStyle)#> reuseIdentifier:CellIdentifier];
}

return cell;
}

0 comments on commit a599469

Please sign in to comment.