Skip to content

Instantly share code, notes, and snippets.

View DevAndArtist's full-sized avatar
🦅
Hacking in Swift

Adrian M. DevAndArtist

🦅
Hacking in Swift
View GitHub Profile
Path Protocol
/swift/stdlib/public/core/AnyHashable.swift:16 _HasCustomAnyHashableRepresentation
/swift/stdlib/public/core/BidirectionalCollection.swift:21 _BidirectionalIndexable
/swift/stdlib/public/core/BridgeObjectiveC.swift:19 _ObjectiveCBridgeable
/swift/stdlib/public/core/Collection.swift:20 _IndexableBase
/swift/stdlib/public/core/Collection.swift:176 _Indexable
/swift/stdlib/public/core/CompilerProtocols.swift:193 _ExpressibleByBuiltinIntegerLiteral
/swift/stdlib/public/core/CompilerProtocols.swift:240 _ExpressibleByBuiltinFloatLiteral
/swift/stdlib/public/core/CompilerProtocols.swift:283 _ExpressibleByBuiltinBooleanLiteral
/// An opaque type that represents a method in a class definition.
public struct Method {
public struct Description {
/**< The name (selector) of the method */
public var selector: Selector
/**< The types of the method arguments */
public var types: UnsafeMutablePointer<Int8>

ContainerViewController

A trully custom container view controller written in Swift 3.0.1. The view of this object is fully resizable and works great with layout constraints.

Todo

  • Mimic UINavigationController without any bar APIs
  • More flexible delegate methods
  • Simple non-interactive transition
  • Interactive transition
final class Storage {
// not empty for testing
var keys: [String] = ["0"]
var values: [Int] = [0]
}
public struct Document {
var _storageReference: Storage
@DevAndArtist
DevAndArtist / endian-conversion-cheat-sheet.swift
Last active October 30, 2024 22:13
A cheat sheet for byte conversion of number types in Swift 3.0
func _convertToBytes<T>(_ value: T, withCapacity capacity: Int) -> [UInt8] {
var mutableValue = value
return withUnsafePointer(to: &mutableValue) {
return $0.withMemoryRebound(to: UInt8.self, capacity: capacity) {
return Array(UnsafeBufferPointer(start: $0, count: capacity))
}
}
@DevAndArtist
DevAndArtist / ForDevice.swift
Created August 26, 2016 18:36
A function to assign device specific value for UIKit.
// Swift 3.0:
// This functuion makes use of the custom operator `?!`:
// https://gist.github.com/DevAndArtist/dad641ee833e60b02fd1db2dbb488c6a
@available(iOS 9.0, *)
func forDevice<T>(
phone: @autoclosure () -> T? = nil,
pad: @autoclosure () -> T? = nil,
tv: @autoclosure () -> T? = nil,
carPlay: @autoclosure () -> T? = nil) -> T {
//
// UnwrapOrTrap.swift
//
infix operator ?! : NilCoalescingPrecedence
/// Performs a nil-coalescing operation, returning the wrapped value of an
/// `Optional` instance or uses the rhs function to stop the program.
///
/// - Parameters:
// we generate the boundary with `A | B` or directly OneOf<A, B>
enum OneOf<...T> {
...case $#(T)
// Bikeshedding variadic enum casses:
// we might need an index to set the value?
init(index: Int, value: T) {
self = .$index(value)
import UIKit
protocol NSLayoutConstraintSearchable: class {}
extension NSLayoutConstraintSearchable {
// this function does add support for UIView and UILayoutGuide
private func getConstraints() -> [NSLayoutConstraint]? {
// only UIView's hold constraints