Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Importing first batch of snippets from Xcode

  • Loading branch information...
commit a59946913f966f7512aa608ec3502dc7563413d4 1 parent 6268f99
@mattt mattt authored
View
14 async.m
@@ -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#>
+ });
+});
View
10 continuation.m
@@ -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
View
15 init.m
@@ -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;
View
11 kvo.m
@@ -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#>"];
@nevyn
nevyn added a note

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".

@mattt Owner
mattt added a note

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
32 lifecycle.m
@@ -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];
+}
View
8 mark.m
@@ -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#>
View
16 tvdel.m
@@ -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;
+ }
+}
View
33 tvds.m
@@ -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;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.