Skip to content

Instantly share code, notes, and snippets.

View vamsiac's full-sized avatar

Vamsi Anguluru vamsiac

View GitHub Profile
@vamsiac
vamsiac / SKActionTransitionColor.swift
Created January 18, 2019 11:16 — forked from johnnyw/SKActionTransitionColor.swift
[SpriteKit] Custom SKAction to transition the fill/stroke color of an SKShapeNode.
import CoreGraphics
import SpriteKit
extension SKAction {
static func transitionStrokeColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {
return transitionColor(from: from, to: to, duration: duration, fill: false)
}
static func transitionFillColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {
import UIKit
import CoreData
class FRCTableViewDataSource: NSObject, UITableViewDataSource {
private unowned let fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult>
let configureCell: (UITableViewCell, IndexPath)-> ()
init(fetchController: NSFetchedResultsController<NSFetchRequestResult>, configureBlock: @escaping (UITableViewCell, IndexPath)-> ()) {
self.fetchedResultsController = fetchController
self.configureCell = configureBlock
import UIKit
import CoreData
public class FRCDelegate: NSObject, NSFetchedResultsControllerDelegate {
private unowned let tableView: UITableView
init(tableView: UITableView) {
self.tableView = tableView
super.init()
import UIKit
typealias DownloadCompletionBlock = (UIImage?) -> Void
class AsyncImageView: UIImageView {
/// Returns the cached image or nil if connection fails.
var completionHandler:((UIImage?)->Void)?
/// Sets the cache policy for the image download request. Default values is .returnCacheDataElseLoad.
import UIKit
protocol CustomAccessoryToolbarDelegate {
var userEnabledFields: [UIView]! {get set}
func previousButtonClicked(_ sender: UIView)
func nextButtonClicked(_ sender: UIView)
func doneButtonClicked(_ sender: UIView)
}
extension CustomAccessoryToolbarDelegate where Self: UIViewController {
@vamsiac
vamsiac / async_error_handling.md
Created August 16, 2016 10:42 — forked from BlameOmar/async_error_handling.md
Asynchronous Error Handling in Swift 2.0

Asynchronous Error Handling in Swift 2.0

As Swift 1.0 did not include support for exceptions, a common error handling pattern was to use a Result enum that either took on a value on success, or an error on failure. In a way, this was superior to using exceptions, since being a instantiable type, Results could be passed around freely, enabling asynchronous code to use the same error handling mechanisim as synchronous code. Using Swift's robust support for custom operators, this also enabled Railway Oriented Programming for more functional oriented programers.

Swift 2.0 introduces throwable errors, which are similar to exceptions. However, like exceptions, thrown errors

@vamsiac
vamsiac / Fetchable.swift
Last active May 2, 2017 13:23 — forked from capttaco/Fetchable.swift
A utility protocol for custom NSManagedObjects that makes querying contexts simpler and more convenient. Requires Swift 2.
import CoreData
protocol Fetchable
{
associatedtype FetchableType: NSManagedObject = Self
static func entityName() -> String
static func objectsInContext(_ context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> [FetchableType]
static func singleObjectInContext(_ context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> FetchableType?
static func objectCountInContext(_ context: NSManagedObjectContext, predicate: NSPredicate?) -> Int
@vamsiac
vamsiac / String.swift
Created December 17, 2015 10:08 — forked from kharrison/String.swift
Swift String Playground Examples
// Swift Standard Librray - String
// Keith Harrison http://useyourloaf.com
// Import Foundation if you want to bridge to NSString
import Foundation
// ====
// Initializing a String
// ====
@vamsiac
vamsiac / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
//Appdelegate.h
CFAbsoluteTime StartTime;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
//In your main.m start your timer
int main(int argc, char *argv[])
{
StartTime = CFAbsoluteTimeGetCurrent();