Skip to content

Instantly share code, notes, and snippets.

View codeactual's full-sized avatar

David Smith codeactual

  • Found Apparatus
  • Portland, OR
View GitHub Profile
@codeactual
codeactual / swift-async-await-example.swift
Created April 10, 2022 15:57 — forked from christianselig/swift-async-await-example.swift
Some questions about async await threading in Swift's new concurrency model.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Task {
// 1️⃣❓ UIViewController is in a MainActor context, so this Task
// will inherit that, so the following pretend expensive call will
// be on the main thread and likely block?
ExpensiveOperationPerformer.doExpensiveLoopAndPrint()
}
@codeactual
codeactual / ANSI.md
Created March 9, 2022 17:58 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@codeactual
codeactual / Animation.md
Created February 21, 2022 19:42 — forked from JeOam/Animation.md
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

Author: https://www.cyanhall.com/

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

@codeactual
codeactual / SwiftUI Tagger.swift
Created February 14, 2022 18:10 — forked from mralexhay/SwiftUI Tagger.swift
A SwiftUI interface for adding tags
//
// TaggerView.swift
//
// Created by Alex Hay on 21/11/2020.
//
// Simple interface for adding tags to an array in SwiftUI
// Example video: https://imgur.com/gallery/CcA1IXp
// alignmentGuide code from Asperi @ https://stackoverflow.com/a/58876712/11685049
import SwiftUI
@codeactual
codeactual / ColorText.swift
Created February 7, 2022 16:19 — forked from davidsteppenbeck/ColorText.swift
Attributed strings in Swift with color attributes [iOS 15+]. Add colors to strings in your Localizable.strings files.
import SwiftUI
struct ColorText: View {
// MARK:- Properties
/// The attributed string to display.
private let attributedString: AttributedString
var body: some View {
@codeactual
codeactual / IceCream.swift
Created February 7, 2022 14:37 — forked from christianselig/IceCream.swift
Example code, simply throw this into a view controller from a sample project.
import UIKit
struct IceCream {
let title: String
let icon: UIImage
}
struct AppSettings {
static var fontSize = 17.0
}
extension Error {
var code: Int { return (self as NSError).code }
var domain: String { return (self as NSError).domain }
var userInfo: [String:Any] { return (self as NSError).userInfo }
func timeAfterWhichToRetry(retryCount: Int) -> TimeInterval? {
// CloudKit suggests us retry too often, so slow us down as we retry a lot, up to 5 minutes
if let suggestedTimeout = suggestedTimeAfterWhichToRetry {
if suggestedTimeAfterWhichToRetry == 0 {
return 0
@codeactual
codeactual / testColorScheme.swift
Created January 17, 2022 18:06 — forked from gavinjerman/testColorScheme.swift
Example code showing how to set color scheme in SwiftUI app using code from https://github.com/writefreely/writefreely-swiftui-multiplatform
import SwiftUI
@main
struct testColorSchemeApp: App {
@StateObject private var appearanceManager = AppearanceManager()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(appearanceManager)
//
// RemindersAppIcon.swift
// RemindersAppIcon
//
// Created by David on 1/5/22.
//
import SwiftUI
struct RemindersAppIcon: View {
@codeactual
codeactual / PomodoroPicker.swift
Created January 11, 2022 14:11 — forked from dmr121/PomodoroPicker.swift
SwiftUI - Snapping horizontal scrolling pomodoro picker
//
// PomodoroPicker.swift
// pomodoro
//
// Created by David Rozmajzl on 1/1/22.
//
import SwiftUI
struct PomodoroPicker<Content, Item: Hashable>: View where Content: View {