Skip to content

Instantly share code, notes, and snippets.

View SuperWomble's full-sized avatar

David SuperWomble

  • Adelaide, South Australia
View GitHub Profile
struct RecursivelyGlowInTheDarkViewModifier: ViewModifier {
let colors: [Color]
func body(content: Content) -> some View {
var modifiedColors = colors // First create a local variable
let nextColor: Color?
if !modifiedColors.isEmpty { // if it is not empty, remove the first element to use it
nextColor = modifiedColors.remove(at: 0)
} else { // or set as nil
nextColor = nil
}
@peantunes
peantunes / GlowInTheDarkViewModifier-first.swift
Last active January 10, 2024 04:57
Glow in the dark View Modifier for SwiftUI
struct GlowInTheDarkViewModifier: ViewModifier {
let active: Bool
@ViewBuilder func body(content: Content) -> some View {
if active {
content
.shadow(color: .yellow, radius: 5)
.shadow(color: .white, radius: 5)
.shadow(color: .green, radius: 5)
.shadow(color: .blue, radius: 5)
.shadow(color: .green, radius: 5)
@atomicbird
atomicbird / wwdc2019-online-sessions.md
Last active May 29, 2020 22:59
WWDC 2019 Online-only Sessions

At WWDC 2019 Apple released some videos directly online, with no corresponding live session. This is a list of those videos with links to the video pages.

Some sessions were presented during WWDC but then split into multiple videos when posted online. This list includes the online versions, since they don't appear in the WWDC schedule. For example WWDC included session 711, "Introducing Combine and Advances in Foundation". This was split into two online videos-- 722, "Introducing Combine", and 723, "Advances in Foundation". Both 722 and 723 are included here.

@timonus
timonus / programmatic-dynamic-images.m
Last active January 1, 2024 12:08
Programmatically create iOS 13 dynamic images
- (UIImage *)dynamicImage
{
UITraitCollection *const baseTraitCollection = /* an existing trait collection */;
UITraitCollection *const lightTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]]];
UITraitCollection *const purelyDarkTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
UITraitCollection *const darkTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, purelyDarkTraitCollection]];
__block UIImage *lightImage;
[lightTraitCollection performAsCurrentTraitCollection:^{
lightImage = /* draw image */;
@kostapappas
kostapappas / customView.swift
Last active November 20, 2021 05:16
Swift 4, custom UIView with explanations
class MyCustomView: UIView {
private var didSetupConstraints = false
//In Swift initializers are not inherited for subclasses by default
override init(frame: CGRect) {
super.init(frame: frame)
}
// Deserialize your object here
@shaps80
shaps80 / 1. UserDefaults+Key.swift
Last active September 25, 2020 08:29
Adds a Swift extension to make UserDefaults more consistent to work with.
//
// UserDefaults.swift
//
// Created by Shaps Benkau on 24/05/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
//
import Foundation
#if os(iOS)
@maxchuquimia
maxchuquimia / runscript.sh
Created April 28, 2018 07:51
Demo of using Swift in a Run Script phase in Xcode
#!/bin/bash
CONFIG_PASSWORD="BE5D2905-0625-4EBF-BCA2-7F6F5D138425"
REQUIRED_CONFIG_FILE_PATH="${SRCROOT}/YourProject/App/Config/Configurations/Config-${CONFIGURATION}.plist"
CONFIG_OUTPUT_PATH="${SRCROOT}/YourProject/App/Config/Configurations/Config.json"
CONFIG_EXTENSION_OUTPUT_PATH="${SRCROOT}/YourProject/App/Config/Configurations/Config+Extension.swift"
set -e
if [ -z "${CONFIGURATION}" ]
@miguelfermin
miguelfermin / PageViewController.swift
Created May 8, 2017 10:05
Demonstrates how to add a UIPageViewController to a UIViewController
//
// ViewController.swift
// PageViewController
//
// Created by Miguel Fermin on 5/8/17.
// Copyright © 2017 MAF Software LLC. All rights reserved.
//
import UIKit
@cotkjaer
cotkjaer / CGRect+Center.swift
Last active November 23, 2023 06:15
Swift extensions to add "center" to CGRect
extension CGRect
{
/** Creates a rectangle with the given center and dimensions
- parameter center: The center of the new rectangle
- parameter size: The dimensions of the new rectangle
*/
init(center: CGPoint, size: CGSize)
{
self.init(x: center.x - size.width / 2, y: center.y - size.height / 2, width: size.width, height: size.height)
import CoreGraphics
private typealias CGPathDumpUtility = CGPath
extension CGPathDumpUtility {
func dump() {
self.apply(info: nil) { info, unsafeElement in
let element = unsafeElement.pointee
switch element.type {