Skip to content

Instantly share code, notes, and snippets.

@keicoder
keicoder / snippet.m
Created February 24, 2014 04:54
objective-c : give object a unique numeric ID (itemId)
//give object a unique numeric ID (itemId)
//ChecklistItem.h
@property (nonatomic, assign) NSInteger itemId;
//ChecklistItem.m
//initWithCoder - for view controllers that are automatically loaded from a nib or Storyboard
//for unfreezing the objects from the file
- (id)initWithCoder:(NSCoder *)aDecoder
{
@keicoder
keicoder / gist:9181595
Last active August 29, 2015 13:56 — forked from troyharris/gist:6877536
objective-c : UITextView - A very hacky way to enable UITextView to scroll to the cursor when typing. I believe I got this from someone on SO but I can't find the original source anymore
- (void)textViewDidChange:(UITextView *)textView {
[self _showTextViewCaretPosition:textView];
}
- (void)textViewDidChangeSelection:(UITextView *)textView {
[self _showTextViewCaretPosition:textView];
}
- (void)_showTextViewCaretPosition:(UITextView *)textView {
@keicoder
keicoder / snippet.m
Created February 24, 2014 03:35
objective-c : basic local notifications
//basic local notifications
#pragma mark - didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
//local notifications test
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:10];
@keicoder
keicoder / snippet.m
Created February 22, 2014 09:08
objective-c : count items
//count items and update table views lable
//loops through the ChecklistItem objects from the items array
//If the item object has its checked property set to NO, increment the local variable count by 1
//When looked at all the objects, return the value of this count to the caller
//Checklist.h
- (int)countUncheckedItems;
//Checklist.m
@keicoder
keicoder / snippet.m
Created February 22, 2014 08:20
objective-c : handleFirstTime
//handleFirstTime
//in DataModel.m
- (void)registerDefaults {
NSDictionary *dictionary = @{
@"ChecklistIndex" : @-1,
@"FirstTime" : @YES
};
@keicoder
keicoder / snippet.m
Created February 22, 2014 08:04
objective-c : using basic NSDictionary
//using basic NSDictionary
//inside DataModel.m
- (void)registerDefaults {
NSDictionary *dictionary = @{
@"ChecklistIndex" : @-1,
@"FirstTime" : @YES //“FirstTime” acts as a boolean value because it’s either yes or no (true or false)
};
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
@keicoder
keicoder / snippet.m
Created February 21, 2014 07:08
objective-c : table view accessory-tapped delegate method
//table view accessory-tapped delegate method
#pragma mark - Accessory-tapped 델리게이트 메소드
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"ListNavigationController"];
@keicoder
keicoder / snippet.m
Last active May 13, 2021 14:02
objective-c : dataModel using plist file and save to documents directory
//dataModel using plist file and save to documents directory
#import "DataModel.h"
#import "Checklist.h" //first time runs the app then create a new Checklist object
@implementation DataModel
#define debug 1
#pragma mark - 다큐먼트 디렉토리
@keicoder
keicoder / snippet.m
Created February 20, 2014 04:47
objective-c : delegate pattern
//delegate pattern
//delegate pattern is commonly used to handle the following situation
//ex)
//screen A opens screen B and at some point screen B needs to communicate back to screen A, for example when it closes.
//The solution is to make A a delegate of B so screen B can send its messages to A whenever it needs to.
//Screen A launches screen B and becomes its delegate
//The cool thing about the delegate pattern is that screen B doesn’t really know anything about screen A.
//It just knows that some object is its delegate. Other than that, screen B doesn’t care who that is. Just like UITableView doesn’t really care about your view controller, only that it delivers table view cells when the table view asks for them.
@keicoder
keicoder / content.m
Last active August 29, 2015 13:56
objective-c : Xcode Console Debug Code
//Xcode Console Debug Code
#define debug 1
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}