Skip to content

Instantly share code, notes, and snippets.

View Daemon-Devarshi's full-sized avatar

Devarshi Kulshreshtha Daemon-Devarshi

View GitHub Profile
@Daemon-Devarshi
Daemon-Devarshi / AppDelegate+CoreData.h-file
Created October 8, 2014 02:59
Separating CoreData stack from AppDelegate via Categaory
//
// AppDelegate+CoreData.h
// Protactinium
//
// Created by Devarshi on 10/8/14.
// Copyright (c) 2014 Devarshi Kulshreshtha. All rights reserved.
//
#import "AppDelegate.h"
@Daemon-Devarshi
Daemon-Devarshi / PasteboardWatcher.swift
Last active October 6, 2023 14:15
A class which performs polling to determine the newly copied url of desired kind in an external app
//
// PasteboardWatcher.swift
// PasteboardWatcher
//
// Created by Devarshi Kulshreshtha on 6/19/15.PasteboardWatcher
// Copyright © 2015 Devarshi Kulshreshtha. All rights reserved.
//
import Cocoa
@Daemon-Devarshi
Daemon-Devarshi / ExtendedArrayController.swift
Created June 20, 2015 20:02
Extended NSArrayController in swift
extension NSArrayController {
/// Method which can be binded in storyboard to remove all objects from array controller
@IBAction func removeAllObjects(sender: AnyObject) {
let range = NSMakeRange(0, self.arrangedObjects.count)
self.removeObjectsAtArrangedObjectIndexes(NSIndexSet(indexesInRange: range))
}
}
@Daemon-Devarshi
Daemon-Devarshi / MySubModule.podspec
Created September 17, 2015 15:54
podspec which contains most often used specifications, copied from http://www.raywenderlich.com/99386/create-cocoapod-swift
Pod::Spec.new do |s|
# 1
s.platform = :ios
s.ios.deployment_target = '8.0'
s.name = "RWPickFlavor"
s.summary = "RWPickFlavor lets a user select an ice cream flavor."
s.requires_arc = true
# 2
@Daemon-Devarshi
Daemon-Devarshi / OnBoardingViewController.swift
Created October 25, 2016 19:58
Plug and play class to implement pagination controller with sample usage
//
// OnBoardingViewController.swift
//
// Created by Devarshi Kulshreshtha on 10/26/16.
// Copyright © 2016 Devarshi. All rights reserved.
//
import UIKit
class OnBoardingViewController: PaginationViewBaseController {
@Daemon-Devarshi
Daemon-Devarshi / Pop.swift
Created October 27, 2016 08:44
Push animation using custom segue
protocol Pop {
func moveBackToParentViewController(currentViewController: UIViewController)
}
extension Pop {
func moveBackToParentViewController(currentViewController: UIViewController) {
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionMoveIn
@Daemon-Devarshi
Daemon-Devarshi / BorderedView.swift
Created December 17, 2016 09:09
Handy code to configure a bordered view using storyboard
//
// BorderedView.swift
//
// Created by Devarshi Kulshreshtha on 17/12/16.
// Copyright © 2016 Devarshi. All rights reserved.
//
import UIKit
@IBDesignable
@Daemon-Devarshi
Daemon-Devarshi / XCTestCase+CoreDataHelper.swift
Created June 19, 2017 09:19
An extension on XCTestCase to setup an in-memory persistent store coordinator
import Foundation
import XCTest
import CoreData
@testable import MainModule
extension XCTestCase {
func setUpInMemoryManagedObjectContext() -> NSManagedObjectContext {
let managedObjectModel = NSManagedObjectModel.mergedModel(from: [Bundle.main])!
@Daemon-Devarshi
Daemon-Devarshi / BinarySearch.swift
Last active July 26, 2017 06:16
Binary Search using Recurssion
/// Performs binary search using Recursion
func binarySearch<T:Comparable>(on array: [T], for targetValue: T, from minIndex: Int, to maxIndex: Int) -> Int? {
// assigning to var so that values can be updated
var min = minIndex
var max = maxIndex
// Obtaining the pivot element
let guessIndex = Int((max + min) / 2)
// Value comparisons
if array[guessIndex] == targetValue {
// Value found :) Return the index!
@Daemon-Devarshi
Daemon-Devarshi / Reusable.swift
Last active August 2, 2017 14:05
A protocol to be used to avoid hardcoding of reuse identifier
protocol Reusable: class {
static var reuseIdentifier: String { get }
}
extension Reusable {
static var reuseIdentifier: String {
// I like to use the class's name as an identifier
// so this makes a decent default value.
return String(describing: self)
}