Skip to content

Instantly share code, notes, and snippets.

Roopesh Chander roop

Block or report user

Report or block roop

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View FutureSwiftyResponderChain
/* This is an alternate responder chain implementation that
DOES NOT work in Swift 2.2, but might in a
hypothetical future version of Swift. */
protocol Command {
}
protocol ResponderChainable {
var nextResponder: ResponderChainable? { get }
}
@roop
roop / SwiftyResponderChain.swift
Created Jun 3, 2016
A responder chain implementation for a hypothetical pure-Swift equivalent for UIKit. More info at: http://roopc.net/posts/2016/swifty-responder-chain/
View SwiftyResponderChain.swift
/* A responder chain implementation for a hypothetical pure-Swift
* equivalent for UIKit.
* More info at: http://roopc.net/posts/2016/swifty-responder-chain/
*/
/* A responder is something that has an optional next responder,
so that we can have a chain of responders. */
protocol Responder {
var nextResponder: Responder? { get }
View FeedsAndFolders.swift
protocol Feed: Equatable {
var url: String { get }
}
func ==<T: Feed>(lhs: T, rhs: T) -> Bool {
return (lhs.url == rhs.url)
}
protocol Folder {
typealias FeedType: Feed
@roop
roop / AutoLayoutHelper.swift
Created Jul 10, 2015
Helper for specifying AutoLayout constraints in code
View AutoLayoutHelper.swift
/*
AutoLayoutHelper.swift is published under the MIT License.
Copyright (C) 2014-15, Roopesh Chander http://roopc.net/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
View ObservationHelper.swift
/*
ObservationHelper.swift is published under the MIT License.
Copyright (C) 2014-15, Roopesh Chander http://roopc.net/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@roop
roop / makemake.pl
Last active Jun 19, 2017
Script to create a Makefile to build your Swift project
View makemake.pl
#!/usr/bin/perl -w
use strict;
# Makefile generator for quick compilation of Swift projects
# By: Roopesh Chander
# Thanks: Andy Matuschak
# Works only for swift-only projects.
# Usage:
# > perl makemake.pl
# > make
View array_copy_semantics_workaround.swift
extension Array {
var unsafePointerToElements: UnsafePointer<T> {
return self.withUnsafePointerToElements { return $0 }
}
subscript (index: Int) -> T {
get {
let ptr = self.unsafePointerToElements
return ptr[index]
}
set(rhs) {
View array_internal_storage.swift
extension Array {
func sharesStorageWith(other: Array<T>) -> Bool {
let thisPtr: UnsafePointer<T> = self.withUnsafePointerToElements { return $0 }
let otherPtr: UnsafePointer<T> = other.withUnsafePointerToElements { return $0 }
return (thisPtr == otherPtr)
}
}
var a1: Array<Int> = [10, 11]
a1.append(20)
View classes_are_reference_types.swift
class MyClass {
var value: Int
init(value v: Int) { value = v }
}
var instanceOfMyClass = MyClass(value: 42)
var assignedInstance2 = instanceOfMyClass
assignedInstance2.value = 2 // Change the copied instance
instanceOfMyClass.value // 2: Original is also changed
View structs_are_value_types.swift
struct MyStruct {
var value: Int = 0
}
var instanceOfMyStruct = MyStruct(value: 42)
var assignedInstance1 = instanceOfMyStruct
assignedInstance1.value = 2 // Change the copied instance
instanceOfMyStruct.value // 42: Original is unchanged
You can’t perform that action at this time.