Skip to content

Instantly share code, notes, and snippets.

View speaktoalvin's full-sized avatar

Alvin speaktoalvin

View GitHub Profile
import Foundation
protocol SomeDelegateProtocol : class {
func firstFunc() -> String
func secondFunc() -> Bool
func thirdFunc() -> Self
}
class MyClass {
weak var delegate : SomeDelegateProtocol?
@speaktoalvin
speaktoalvin / .aliases
Last active September 3, 2015 19:44 — forked from codejets/.aliases
.aliases which i import into my bashrc or zshrc
# Get the Git branch
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Custom bash prompt
#
# Includes custom character for the prompt, path, and Git branch name.
#
# Source: kirsle.net/wizards/ps1.html
//
// WatchSessionManager.swift
// WatchConnectivityDemo
//
// Created by Natasha Murashev on 9/3/15.
// Copyright © 2015 NatashaTheRobot. All rights reserved.
//
import WatchConnectivity
@speaktoalvin
speaktoalvin / IAPHelper.txt
Last active April 29, 2021 04:07
In App Purchase in Swift, with Receipt Validation
import UIKit
import StoreKit
//MARK: SKProductsRequestDelegate
extension IAPHelpers : SKProductsRequestDelegate
{
func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse)
{
@speaktoalvin
speaktoalvin / gcd
Created October 14, 2015 07:20
Grand Central Dispatch
// An easy way to get different queue's in your project.
//
// GCDMan.swift
// GCDGhost
//
// Created by Alvin Varghese on 15/09/15.
// Copyright (c) 2015 iDreamCode. All rights reserved.
//
// Example JSON
{
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"relationships": {
"author": {
// Adding Screen Edge Pan to the presenting viewController
@IBAction func showSafariViewController(sender: AnyObject) {
let safariViewController = IDMSafariViewController(URL: NSURL(string: "http://idreamcode.com")!)
safariViewController.delegate = self;
safariViewController.transitioningDelegate = self.transitionManager
safariViewController.modalPresentationStyle = UIModalPresentationStyle.Custom
self.transitionManager.transitionTo = kToManageReourceVC
self.presentViewController(safariViewController, animated: true) { () -> Void in
let recognizer = UIScreenEdgePanGestureRecognizer(target: self, action: "handleGesture:")
// Handling the pan gesture method
func handleGesture(recognizer:UIScreenEdgePanGestureRecognizer) {
switch recognizer.state {
case .Began: ()
case .Changed:dismissViewControllerAnimated(true, completion: nil)
case .Ended, .Cancelled:
(recognizer.velocityInView(view).x < 0) ? () :
dismissViewControllerAnimated(true, completion: nil)
//
// HelloTransition.swift
// The Top Fives
//
// Created by Alvin Varghese on 9/13/15.
// Copyright (c) 2015 I dream Code. All rights reserved.
//
import UIKit
// Main ViewController
import UIKit
import SafariServices
class ViewController: UIViewController, SFSafariViewControllerDelegate, UIViewControllerTransitioningDelegate {
let transitionManager : HelloTransition = HelloTransition()
@IBAction func showSafariViewController(sender: AnyObject){