Skip to content

Instantly share code, notes, and snippets.

View twof's full-sized avatar
🐦
Having an animated discussion with the Swift compiler

Alex Reilly twof

🐦
Having an animated discussion with the Swift compiler
View GitHub Profile
import UIKit
class ViewController: UIViewController {
let movableView: UIView = {
let view = UIView(frame: .zero)
view.translatesAutoresizingMaskIntoConstraints = false
view.accessibilityIdentifier = "MovableView"
view.backgroundColor = .red
return view
}()
func crud<ParentType>(
at path: PathComponentsRepresentable...,
parent relation: KeyPath<ChildType, Parent<ChildType, ParentType>>,
_ either: OnlyExceptEither<ParentRouterMethod>,
relationConfiguration: ((CrudParentController<ChildType, ParentType>) -> Void)?
) where
ParentType: Model & Content,
ChildType.Database == ParentType.Database,
ParentType.ID: Parameter
This file has been truncated, but you can view the full file.
-> Core
Core (3.4.4) - Analyzing on iOS 10.0 platform.
Preparing
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-App`: (``)
This file has been truncated, but you can view the full file.
-> Core
Core (3.4.4) - Analyzing on iOS 10.0 platform.
Preparing
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-App`: (``)
This file has been truncated, but you can view the full file.
-> Core
Core (3.4.4) - Analyzing on iOS 10.0 platform.
Preparing
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-App`: (``)
@twof
twof / PagedViewController.swift
Created November 8, 2018 07:02
A simple to use page controller
import UIKit
class PagedViewController: UIViewController {
// MARK: - Properties
private static let defaultPageControlConstraints: (PagedViewController) -> ([NSLayoutConstraint])
= { (pagedViewController: PagedViewController) in
return [
pagedViewController.pageControl.bottomAnchor.constraint(
equalTo: pagedViewController.scrollView.bottomAnchor,
$ git clone https://github.com/twof/VaporMailgunService
Cloning into 'VaporMailgunService'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 244 (delta 4), reused 13 (delta 2), pack-reused 225
Receiving objects: 100% (244/244), 47.44 KiB | 0 bytes/s, done.
Resolving deltas: 100% (85/85), done.
$ cd VaporMailgunService/
$ vapor build
// This first solution is the ideal one to come up with if the interviewer said they were looking for a demonstration of
// OOP design concepts. It's not generic right now, but I'll try and update it later to fix that. This is working Swift code,
// so feel free to paste it into a playground if you'd like to play with it
import Foundation
protocol Node {
func evaluate() -> Int
}
@twof
twof / ReflectiveDecodable.swift
Created March 3, 2018 05:46
Codable that automatically decodes with default vals
import Foundation
func iterateEnum<T: Hashable>(_: T.Type) -> AnyIterator<T> {
var i = 0
return AnyIterator {
let next = withUnsafeBytes(of: &i) { $0.load(as: T.self) }
if next.hashValue != i { return nil }
i += 1
return next
}
class Node<T>{
var content: T
var next: Node?
init(content: T, next: Node?){
self.content = content
self.next = next
}
}