Skip to content

Instantly share code, notes, and snippets.

View odrobnik's full-sized avatar

Oliver Drobnik odrobnik

View GitHub Profile
@odrobnik
odrobnik / NavPicker.swift
Last active June 16, 2023 01:03
Trying to emulate Picker behaviour inside a List
//
// NavPicker.swift
// ColorCore Demo
//
// Created by Oliver Drobnik on 09.02.21.
//
import SwiftUI
public struct NavPicker<Label, Items> : View where Label : View, Items: CustomStringConvertible & Identifiable
@odrobnik
odrobnik / ContentView.swift
Last active August 15, 2020 09:50
So far it outputs the frames of the cells, but I am stuck trying to hide the ones that are outside of the widget
import SwiftUI
struct RegularEventCell: View {
let color: Color
let title: String
let description: String?
var body: some View {
@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);
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 December 7, 2016 13:53
Convenience method creating a new image by drawing into a context
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()!
public enum VanillaRequestError: Error
{
case unexpectedResult(String)
case restfulError(NSError)
}
// the result from a Vanilla API request
public enum VanillaRequestResult<T>
{
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)
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
{