Skip to content

Instantly share code, notes, and snippets.

View jen2's full-sized avatar

Jen Sipila jen2

  • New York, New York
View GitHub Profile
@jen2
jen2 / ViewController.swift
Created May 8, 2017 00:25
"Securing user data with Keychain for iOS" retrievePasswordButtonTapped implementation.
import UIKit
import SwiftKeychainWrapper
class ViewController: UIViewController {
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@jen2
jen2 / ViewController.swift
Created May 8, 2017 00:23
"Securing user data with Keychain for iOS" savePasswordButtonTapped implementation.
import UIKit
import SwiftKeychainWrapper
class ViewController: UIViewController {
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@jen2
jen2 / ViewController.swift
Created May 8, 2017 00:21
"Securing user data with Keychain for iOS" Initial set up.
import UIKit
import SwiftKeychainWrapper
class ViewController: UIViewController {
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@jen2
jen2 / ViewController.m
Created May 7, 2017 23:56
"Make a Custom UIGestureRecognizer in Objective-C" ViewController.m File and Selector Method.
#import “ViewController.h”
#import “zLetterGestureRecognizer.h”
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addGestureRecognizer:[[ZLetterGestureRecognizer alloc] initWithTarget:self action:@selector(zLetterMade:)]];
@jen2
jen2 / ZLetterGestureRecognizer.m
Created May 7, 2017 23:53
"Make a Custom UIGestureRecognizer in Objective-C" Touches Ended & Cancelled Methods.
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
[self reset];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
self.state = UIGestureRecognizerStateCancelled;
[self reset];
}
@jen2
jen2 / ZLetterGestureRecognizer.m
Created May 7, 2017 23:51
"Make a Custom UIGestureRecognizer in Objective-C" Touches Moved Method.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event]; //A
if ((self.state == UIGestureRecognizerStateFailed) || (self.state == UIGestureRecognizerStateRecognized)) { //B
return;
}
UIView *superView = [self.view superview]; //C
CGPoint currentPoint = [touches.anyObject locationInView:superView];
CGPoint previousPoint = [touches.anyObject previousLocationInView:superView];
if ((self.strokePart == 0) && ((currentPoint.x — self.firstTap.x) > 20.00) && (currentPoint.x > previousPoint.x) &&
@jen2
jen2 / ZLetterGestureRecognizer.m
Created May 7, 2017 23:36
"Make a Custom UIGestureRecognizer in Objective-C" Touches Began Method.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
self.strokePrecision = 10.0; //A
if (touches.count > 1) {
self.state = UIGestureRecognizerStateFailed; // B
return;
}
self.firstTap = [touches.anyObject locationInView: self.view.superview]; //C
}
@jen2
jen2 / ViewController.m
Created May 7, 2017 20:31
Removing the listener NSNotification in Objective-C for "Broadcasting with NSNotification Center."
[[NSNotificationCenter defaultCenter] removeObserver:someObserver];
//However to remove one particular notification from being observed it is best to use the following.
[[NSNotificationCenter defaultCenter] removeObserver:self name:notificationName object:nil];
@jen2
jen2 / ViewController.m
Created May 7, 2017 20:29
Pass userInfo with NSNotification in Objective-C for "Broadcasting with NSNotification Center."
NSDictionary* userInfoDictionary = @{@”name”: @”Bob Smith”};
[[NSNotificationCenter defaultCenter] postNotificationName:@”SomeActionIsComplete” object:nil userInfo:userInfoDictionary];
@jen2
jen2 / ViewController.m
Created May 7, 2017 20:27
Set up listener for NSNotification in Objective-C for "Broadcasting with NSNotification Center."
[[NSNotificationCenter defaultCenter] addObserverForName:@”SomeActionIsComplete” object:nil queue:nil usingBlock:^(NSNotification *note)
{
NSLog(@”The action I was waiting for is complete!!!”);
[self dismissViewControllerAnimated:YES completion:nil];
}];