Skip to content

Instantly share code, notes, and snippets.

Christian Tietze DivineDominion

Block or report user

Report or block DivineDominion

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
@IanKeen
IanKeen / Decodable+Random.swift
Last active Mar 8, 2019
Custom Decoder that can be used to create Decodable instances that are populated with random values
View Decodable+Random.swift
import Foundation
extension Decodable {
public static func randomInstance() throws -> Self {
let decoder = RandomDecoder()
return try Self(from: decoder)
}
}
private class RandomDecoder: Decoder {
@DivineDominion
DivineDominion / cocoaconv.rb
Last active Sep 28, 2018
Convert libMultiMarkdown enums to Swift-bridgeable NS_ENUMs. Pass the path to libMultiMarkdown.h to the script when running.
View cocoaconv.rb
#!/usr/bin/env ruby
require 'optparse'
CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
FALLBACK_PATH = File.join(CURRENT_PATH, "..", "build-xcode", "Debug", "include", "libMultiMarkdown", "libMultiMarkdown.h")
options = {:mode => :nsenum}
OptionParser.new do |parser|
parser.banner = "Usage: #{$0} [options] path/to/libMultiMarkdown.h"
@AliSoftware
AliSoftware / SwiftCopying.swift
Last active Aug 24, 2017
TypeSafe copy()/mutableCopy() (NSCopying/NSMutableCopying) in Swift
View SwiftCopying.swift
import Foundation
//: Swift type-safe protocol versions of (Mutable)Copying
protocol SwiftCopying {
associatedtype NonMutableType = Self
func clone() -> NonMutableType
}
extension SwiftCopying where Self: NSCopying {
func clone() -> NonMutableType {
return self.copy() as! NonMutableType
@sjoerdvisscher
sjoerdvisscher / minimal.swift
Created Jun 28, 2017
Using Decodable to generate a minimal value
View minimal.swift
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
}
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
View EmbedFrameworksScript.sh
#!/bin/sh
set -e
# set your Frameworks path here
FRAMEWORKS_DIR="${SRCROOT}/../Frameworks/${PLATFORM_NAME}"
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
@khanlou
khanlou / Quicksort.swift
Created Dec 9, 2016
Quicksort - the only use for partition(by:) I could find
View Quicksort.swift
import Foundation
extension Array where Element: Comparable {
mutating func quickSort() {
self[self.indices].quickSort()
}
}
extension ArraySlice where Element: Comparable {
mutating func quickSort() {
@Gurdeep0602
Gurdeep0602 / AppStoryboard.swift
Last active May 6, 2019
AppStoryboard enumeration
View AppStoryboard.swift
//
// AppStoryboards.swift
// AppStoryboards
//
// Created by Gurdeep on 15/12/16.
// Copyright © 2016 Gurdeep. All rights reserved.
//
import Foundation
import UIKit
@russbishop
russbishop / TypeErasure.swift
Last active Aug 2, 2018
Type erasure with multiple adopting types
View TypeErasure.swift
// Paste me into a playground!
import Cocoa
//: # Basic Setup
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
}
View valueForKeyTest.swift
//: Playground - noun: a place where people can play
import Cocoa
// When you’re downloading objects from the web, it’s common to need to merge changes
// from the server to already-existing local objects. (If your data model allows for
// mutable objects, as with Core Data, that is.)
//
// The below is a Swift translation of how I’ve done this in Objective-C.
// Note that it works just fine in Swift — though it does require NSObject subclasses.
@preble
preble / NSTextStorageSubclass.swift
Created Feb 9, 2016
Base subclass of NSTextStorage in Swift
View NSTextStorageSubclass.swift
import Cocoa
@objc
class SomeTextStorage: NSTextStorage {
private var storage: NSMutableAttributedString
override init() {
storage = NSMutableAttributedString(string: "", attributes: nil)
super.init()
You can’t perform that action at this time.