Skip to content

Instantly share code, notes, and snippets.

Oliver Drobnik odrobnik

Block or report user

Report or block odrobnik

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 Refreshable.swift
@objc protocol Refreshable
{
/// The refresh control
var refreshControl: UIRefreshControl? { get set }
/// The table view
var tableView: UITableView! { get set }
/// the function to call when the user pulls down to refresh
@objc func handleRefresh(_ sender: Any);
View expectation.swift
func testHangSquareBracket()
{
let input = "Text [-( Text"
let expectation = self.expectation(description: "Should not hang")
DispatchQueue.global().async {
let builder = BBCodeAttributedStringBuilder(bbcode: input)
let output = builder.attributedString
XCTAssertNotNil(output)
@odrobnik
odrobnik / UIImage+Util.swift
Created Dec 7, 2016
Convenience method creating a new image by drawing into a context
View UIImage+Util.swift
import UIKit
extension UIImage
{
/// Creates an image from drawing into a context
convenience init(size: CGSize, opaque: Bool = true, operations: (CGContext)->())
{
UIGraphicsBeginImageContextWithOptions(size, opaque, 0)
let ctx = UIGraphicsGetCurrentContext()!
View TypeInfer.swift
public enum VanillaRequestError: Error
{
case unexpectedResult(String)
case restfulError(NSError)
}
// the result from a Vanilla API request
public enum VanillaRequestResult<T>
{
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 URL: NSURL?
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)
You can’t perform that action at this time.