Skip to content

Instantly share code, notes, and snippets.

🤔
Why is this even a feature?

Zachary Waldowski zwaldowski

🤔
Why is this even a feature?
Block or report user

Report or block zwaldowski

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
@zwaldowski
zwaldowski / EventGenerator.swift
Created Apr 26, 2019
UIKit Touch Synthesis (Hacks! Hacks hacks! Hacks!)
View EventGenerator.swift
import UIKit
import ObjectiveC.runtime
// MARK: - IOKit
@objc private protocol IOHIDEvent: NSObjectProtocol {}
private struct IOHIDDigitizerEventMask: OptionSet {
let rawValue: UInt32
init(rawValue: UInt32) { self.rawValue = rawValue }
@zwaldowski
zwaldowski / DoneAccessoryView.swift
Created Feb 11, 2019
iOS Done Accessory Bar — The two versions below are mutually exclusive
View DoneAccessoryView.swift
import UIKit
class DoneAccessoryView: UIInputView {
private let toolbar = UIToolbar()
init() {
super.init(frame: .zero, inputViewStyle: .default)
translatesAutoresizingMaskIntoConstraints = false
allowsSelfSizing = true
@zwaldowski
zwaldowski / CardPresenting.swift
Last active Feb 10, 2019
iOS presentation controller for bottom-focused cards using Auto Layout - https://www.icloud.com/iclouddrive/0wJzCDOwwXTRF53bM4xWLbYag#card-magic-ii
View CardPresenting.swift
import UIKit
private class CardPresenter: UIPresentationController {
private let dimmingView = UIView()
private let roundingView = UIView()
// MARK: -
override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
View solar.plist
{
si = (
{
a = "-0.3427528387535028";
i = 0;
o = 1;
z = "270.9334057827345";
},
{
a = "-10.23975864472505";
View PHAsset+LegacyURL.swift
import Photos
private extension Collection where Element == URLQueryItem {
subscript(_ name: String) -> String? {
return first { $0.name == name }?.value
}
}
@zwaldowski
zwaldowski / Validate.swift
Created Feb 5, 2018
Non-nil validation using KeyPath
View Validate.swift
import Foundation
struct Test {
var a: String?
var b: Int?
var c: NSObject?
var x = 42
enum Error: Swift.Error {
@zwaldowski
zwaldowski / Digest.swift
Last active May 3, 2018
Swift 4 CC_SHA1 and fast toHexString extensions
View Digest.swift
import Foundation
private func loadCSymbol<T>(named name: String, of _: T.Type = T.self) -> T {
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
guard let sym = dlsym(RTLD_DEFAULT, name) else { preconditionFailure(String(cString: dlerror())) }
return unsafeBitCast(sym, to: T.self)
}
private let CC_SHA1_DIGEST_LENGTH = 20
private let CC_SHA1: @convention(c) (UnsafeRawPointer, Int32, UnsafeMutablePointer<UInt8>) -> UnsafeMutablePointer<UInt8> = loadCSymbol(named: "CC_SHA1")
View nonnull.m
#import <Foundation/Foundation.h>
typedef void(^SomeBlock)(void);
@interface Foo: NSObject
// If this one isn't marked `_Nonnull`, a caller of the class
// won't warn.
- (void)doAThingWithCompletionHandler:(_Nonnull SomeBlock)handler;
@zwaldowski
zwaldowski / KeyedCodable.swift
Last active Aug 7, 2017
Swift 4 Beta 5 NSKeyed{Una,A}rchiver Codable Support
View KeyedCodable.swift
import Foundation
// Stolen from https://github.com/ole/whats-new-in-swift-4/blob/master/Whats-new-in-Swift-4.playground/Pages/Encoding%20and%20decoding.xcplaygroundpage/Contents.swift#L14-L31
struct Card: Codable, Equatable {
enum Suit: String, Codable {
case clubs, spades, hearts, diamonds
}
enum Rank: Int, Codable {
case two = 2, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace
@zwaldowski
zwaldowski / A-Swift-UTI.swift
Last active May 9, 2019
MobileCoreServices Swift audit
View A-Swift-UTI.swift
let swift = UTType.swiftSource
print(swift) // => Swift Source Code
print(swift.rawValue) // public.swift-source
print(swift.conforms(to: .sourceCode)) // => true
print(swift.declaration?[.conformsTo] as Any) // [ "public.source-code" ]
print(swift.declaringBundleURL as Any) // => /System/Library/CoreServices/MobileCoreTypes.bundle
print(swift.isDeclared) // => true
print(swift.isDynamic) // => false
print(swift.preferredTag(for: .filenameExtension) as Any) // => "swift"
print(UTType(preferredTag: "swift", for: .filenameExtension, conformingTo: nil) == swift) // => "true"
You can’t perform that action at this time.