Skip to content

Instantly share code, notes, and snippets.


Oliver Drobnik odrobnik

View GitHub Profile
View NSRegularExpression+Substituation.swift
import Foundation
extension NSRegularExpression
public func substitutingMatches(in string: String, options: NSRegularExpression.MatchingOptions = [], subsituated substitution: @escaping (NSTextCheckingResult)->(String?)) -> String
let nsString = string as NSString
let length = nsString.length
let entireString = NSRange(location: 0, length: length)
View RawValueConvertible.swift
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)->())
View converting assignment.swift
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)
View TableSectionFooterView.swift
import UIKit
class TableSectionFooterView: UIView
var section: Int = 0
var limitMovementToUpwards: Bool = false
override var frame: CGRect
View gist:417af9fbd8c54d3f722f9dd29841f34a
/// The current element attributes state
internal struct TagAttributes
var tagName: String!
var imageURL: NSURL?
var isUnderlined: Bool = false
var isStriken: Bool = false
View extension.swift
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)
View extension.swift
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)
View BarCodeKit.podspec do |spec| = 'BarCodeKit'
spec.version = '1.3.1'
spec.license = 'BSD'
spec.source = { :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 = ''
spec.summary = 'A framework to generate bar codes on iOS or Mac.'
odrobnik / batchdeletion.swift
Created Apr 25, 2016
Backwards-compatible batch deletion
View batchdeletion.swift
extension NSPersistentStoreCoordinator
func batchDelete(fetchRequest: NSFetchRequest) throws
// create a worker
let context = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
context.persistentStoreCoordinator = self
var retError: NSError!
View gist:bbfb369fe66de722940d
enum Result
case Success()
case Error(error: NSError)
case Properties(nodes: [WebDAVNode])
typealias WebDAVRequestCompletion = (Result)->()
func listDirectory(path: String, completion: WebDAVRequestCompletion?)