Skip to content

Instantly share code, notes, and snippets.

View odrobnik's full-sized avatar

Oliver Drobnik odrobnik

View GitHub Profile
import Foundation
// value types which are convertible to and from a Double raw value
protocol RawValueConvertible
{
init(_ rawValue: Double)
var rawValue: Double { get set }
}
func enumerateRawValues<T: RawValueConvertible>(from: T, to: T, unitDivisor: T, block: (_ value: T)->())
func ~= <T>(lhs: inout T?, object: Any?)
{
lhs = object as? T
}
func ~= (lhs: inout URL?, object: Any?)
{
if let string = object as? String
{
lhs = URL(string: string)
import UIKit
class TableSectionFooterView: UIView
{
var section: Int = 0
var limitMovementToUpwards: Bool = false
override var frame: CGRect
{
/// The current element attributes state
internal struct TagAttributes
{
var tagName: String!
var URL: NSURL?
var imageURL: NSURL?
var isUnderlined: Bool = false
var isStriken: Bool = false
extension Dictionary where Key: String, Value: NSFileWrapper
{
mutating func renameBundleResource(oldName: String, newName: String)
{
// remove extension
let prefix = (oldName as NSString).stringByDeletingPathExtension
// find all files belonging to this resource
let fileNames = keys.sort().filter { (key) -> Bool in
return key.hasPrefix(prefix)
public extension CollectionType where Generator.Element == NSIndexPath
{
func indexPathsWithSectionModified(by modifier: Int) -> [NSIndexPath]
{
var modifiedIndexPaths = [NSIndexPath]()
for indexPath in self
{
let modifiedIndexPath = NSIndexPath(forItem: indexPath.item, inSection: indexPath.section + modifier)
modifiedIndexPaths.append(modifiedIndexPath)
Pod::Spec.new do |spec|
spec.name = 'BarCodeKit'
spec.version = '1.3.1'
spec.license = 'BSD'
spec.source = { :git => 'https://github.com/Cocoanetics/BarCodeKit.git', :tag => spec.version.to_s }
spec.ios.source_files = 'Core/Source/iOS/*.{h,m}', 'Core/Source/*.{h,m}', 'Core/*.h'
spec.osx.source_files = 'Core/Source/Mac/*.{h,m}', 'Core/Source/*.{h,m}', 'Core/*.h'
spec.requires_arc = true
spec.homepage = 'http://www.cocoanetics.com/parts/barcodekit/'
spec.summary = 'A framework to generate bar codes on iOS or Mac.'
@odrobnik
odrobnik / batchdeletion.swift
Created April 25, 2016 08:46
Backwards-compatible batch deletion
extension NSPersistentStoreCoordinator
{
func batchDelete(fetchRequest: NSFetchRequest) throws
{
// create a worker
let context = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
context.persistentStoreCoordinator = self
var retError: NSError!
enum Result
{
case Success()
case Error(error: NSError)
case Properties(nodes: [WebDAVNode])
}
typealias WebDAVRequestCompletion = (Result)->()
func listDirectory(path: String, completion: WebDAVRequestCompletion?)
// Swift version of https://developer.apple.com/library/mac/technotes/tn2084/_index.html
@IBAction func testButtonPushed(sender: AnyObject) {
let URL = NSBundle.mainBundle().URLForResource("SendFinderMessage", withExtension: "scpt")!
var errors: NSDictionary?
let script = NSAppleScript(contentsOfURL: URL, error: &errors)!