Skip to content

Instantly share code, notes, and snippets.

@alemar11
alemar11 / Activity.swift
Created February 11, 2020 13:59 — forked from zwaldowski/Activity.swift
os_activity_t for Swift 3
//
// Activity.swift
//
// Created by Zachary Waldowski on 8/21/16.
// Copyright © 2016 Zachary Waldowski. Licensed under MIT.
//
import os.activity
private final class LegacyActivityContext {
//
// FacebookReactions.swift
//
// Created by Fabio Giolito on 10/06/2019.
// Follow me: https://twitter.com/fabiogiolito
//
import SwiftUI
struct FacebookReactions : View {
//
// InstaStories.swift
// SwiftUITests
//
// Created by Fabio Giolito on 23/06/2019.
// Copyright © 2019 Fabio Giolito. All rights reserved.
//
import Combine
import SwiftUI
public struct NilError: Error, CustomStringConvertible {
let file: String
let line: Int
public init(file: String = #file, line: Int = #line) {
self.file = file
self.line = line
}
@alemar11
alemar11 / Switch.swift
Created April 26, 2019 14:53 — forked from nathantannar4/Switch.swift
Re-Engineering UISwitch
//
// Switch.swift
// Re-Engineering UISwitch
//
// Created by Nathan Tannar on 15/12/18.
// Copyright © 2018 Nathan Tannar. All rights reserved.
//
import UIKit
@alemar11
alemar11 / AdaptiveTraitsContainer.swift
Created April 14, 2019 22:15 — forked from douglashill/AdaptiveTraitsContainer.swift
Experimenting altering an iOS app size class to be responsive to the Dynamic Text size.
import UIKit
/// A wrapper view controller that makes the horizontal size class
/// be based on both the Dynamic Text size and the width available.
class AdaptiveTraitsContainer: UIViewController {
let wrappedViewController: UIViewController
init(wrappedViewController: UIViewController) {
self.wrappedViewController = wrappedViewController
super.init(nibName: nil, bundle: nil)
@alemar11
alemar11 / helpers.swift
Created April 8, 2019 20:57 — forked from kastiglione/helpers.swift
Swift helpers, and the lldb setup to use them. Presented @ SLUG https://speakerdeck.com/kastiglione/advanced-debugging-and-swift
extension UIView {
/// Example: call someView.nudge(0, 30)
func nudge(_ dx: CGFloat, _ dy: CGFloat) {
self.frame = self.frame.offsetBy(dx: dx, dy: dy)
CATransaction.flush()
}
}
extension UIView {
/// Example: po UIView.root
@alemar11
alemar11 / Hacking UIView Animation Blocks.md
Created February 11, 2019 15:05 — forked from nicklockwood/Hacking UIView Animation Blocks.md
This article was originally written for objc.io issue 12, but didn't make the cut. It was intended to be read in the context of the other articles, so if you aren't familiar with concepts such as CALayer property animations and the role of actionForKey:, read the articles in that issue first.

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.

@alemar11
alemar11 / scanner.swift
Created February 6, 2019 14:10 — forked from chriseidhof/scanner.swift
Scanning Sequences
import Foundation
// Alternatives to `Scanner` (before: `NSScanner`).
// A scanner only needs a way to peek and to move to the next token.
protocol ScannerProtocol {
associatedtype Token: Equatable
var peek: Token? { get }
mutating func moveToNextToken()
@alemar11
alemar11 / KeyboardTableView.swift
Created January 11, 2019 12:21 — forked from douglashill/KeyboardTableView.swift
A UITableView that allows navigation and selection using a hardware keyboard.
// Douglas Hill, December 2018
import UIKit
/// A table view that allows navigation and selection using a hardware keyboard.
/// Only supports a single section.
class KeyboardTableView: UITableView {
// These properties may be set or overridden to provide discoverability titles for key commands.
var selectAboveDiscoverabilityTitle: String?
var selectBelowDiscoverabilityTitle: String?