Skip to content

Instantly share code, notes, and snippets.

@alladinian
alladinian / Iso3166_1a2.swift
Created December 8, 2023 21:02 — forked from proxpero/Iso3166_1a2.swift
A Swift 4.0 enum representing ISO 3166-1 alpha-2 (two letter country codes) Includes properties for country name and unicode flag.
// taken 2018-03-19 from wikipedia. https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
enum Iso3166_1a2: String {
case af = "AF"
case ax = "AX"
case al = "AL"
case dz = "DZ"
case `as` = "AS"
case ad = "AD"
case ao = "AO"
import Foundation
// Just for clarity of intention
typealias AbsolutePoint = CGPoint
typealias RelativePoint = CGPoint
func * (lhs: CGSize, rhs: CGSize) -> CGSize {
.init(width: lhs.width * rhs.width, height: lhs.height * rhs.height)
}
struct TimingCurveView: View {
@State var value: CGFloat = 0
@State var cp1: RelativePoint = .zero
@State var cp2: RelativePoint = .zero
let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect()
var animation: Animation {
Animation.timingCurve(
struct CurveEditorView: View {
// 1
private let initialPoint0: CGSize = .init(width: 0.4, height: 0.3)
private let initialPoint1: CGSize = .init(width: 0.6, height: 0.6)
// 2
@State private var offsetPoint0: CGSize = .zero
@State private var offsetPoint1: CGSize = .zero
struct CurveShape: Shape {
let cp0, cp1: RelativePoint
func path(in rect: CGRect) -> Path {
Path { p in
p.move(to: CGPoint(x: 0, y: rect.size.height))
p.addCurve(to: CGPoint(x: rect.size.width, y: 0),
control1: cp0 * rect.size,
control2: cp1 * rect.size)
}
}
struct Draggable: ViewModifier {
@State var isDragging: Bool = false
@State var offset: CGSize = .zero
@State var dragOffset: CGSize = .zero
var onChanged: ((CGSize) -> Void)?
var onEnded: ((CGSize) -> Void)?
func body(content: Content) -> some View {
struct ControlPointHandle: View {
private let size: CGFloat = 20
var body: some View {
Circle()
.frame(width: size, height: size)
.overlay(
Circle()
.stroke(Color.white, lineWidth: 2)
)
.offset(x: -size/2, y: -size/2)
@alladinian
alladinian / SwiftUICocoaApp.swift
Last active April 21, 2022 18:21
A super simple Cocoa App boilerplate for SwiftUI prototyping _without_ Xcode
import Cocoa
import SwiftUI
func startApp(content: NSView) {
let app = NSApplication.shared
let menubar = NSMenu()
let appMenuItem = NSMenuItem()
let appMenu = NSMenu()
let appName = ProcessInfo.processInfo.processName
let quitTitle = "Quit \(appName)"
import UIKit
import PlaygroundSupport
var addresses = Set<String>()
class MyCell: UITableViewCell {
required init?(coder: NSCoder) {
super.init(coder: coder)
}
ee_TG Ewe (Togo)
kam_KE Kamba (Kenya)
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)
kab_DZ Kabyle (Algeria)
es_CO Spanish (Colombia)
es_PA Spanish (Panama)
az_Latn Azerbaijani (Latin)
en_NZ English (New Zealand)