Skip to content

Instantly share code, notes, and snippets.

@carlynorama
carlynorama / OptionalChildrenIntrospection.swift
Last active November 2, 2022 22:59
Add this to any Struct if you want a string of all the optional values that actually have defined content.
var whatDoIHave:String {
let mirror = Mirror(reflecting: self)
var itemsToDisplay:[String] = []
for child in mirror.children {
//print("key: \(child.label), value: \(child.value)")
if child.value is ExpressibleByNilLiteral {
let typeDescription = object_getClass(child.value)?.description() ?? ""
if !typeDescription.contains("Null") && !typeDescription.contains("Empty") {
itemsToDisplay.append(child.label ?? "no_key")
@carlynorama
carlynorama / HTMLtoSwiftUI.swift
Last active October 31, 2022 21:47
Rendering HTML as AttributedString in a scroll view without crahsing.
//
// ContentView.swift
// HTMLTests
//
// Created by Carlyn Maw on 10/30/22.
//
//https://www.hackingwithswift.com/example-code/uikit/how-to-load-a-html-string-into-a-wkwebview-or-uiwebview-loadhtmlstring
//https://developer.apple.com/forums/thread/682431
//https://developer.apple.com/documentation/foundation/attributedstring
//
// ResponseService.swift
// NetworkingExample
//
// Created by Carlyn Maw on 10/29/22.
//
import Foundation
enum RequestServiceError:Error, CustomStringConvertible {
@carlynorama
carlynorama / StreamWrappedPublisher.swift
Last active September 27, 2022 05:06
Comparing an AsyncPublisher vs an AsyncPublisher wrapped in a stream.
import Foundation
import SwiftUI
actor TestService {
static let shared = TestService()
@MainActor @Published var counter:Int = 0 {
@carlynorama
carlynorama / debouncingTextField.swift
Last active September 17, 2022 16:54
Debouncing Text Field
//
// DebouncingTextField.swift
// LocationSearchResults
//
// Created by Labtanza on 8/13/22.
// https://stackoverflow.com/questions/66164898/swiftui-combine-debounce-textfield
// https://stackoverflow.com/questions/62635914/initialize-stateobject-with-a-parameter-in-swiftui
import SwiftUI
@carlynorama
carlynorama / NotificationTasks.swift
Last active September 16, 2022 15:10
NotificationCenter async ways to share with a view
//
// ComparingApproaches.swift
// NotificationTasks
//
// Created by carlynorama on 9/15/22.
//
//
// https://www.donnywals.com/comparing-lifecycle-management-for-async-sequences-and-publishers/ (code appraoch has been depricated since written)
// for the sequence: https://talk.objc.io/episodes/S01E303-visualizing-async-algorithms-merging-async-streams
// for the stream: https://www.hackingwithswift.com/quick-start/concurrency/how-to-create-a-custom-asyncsequence
@carlynorama
carlynorama / HandyGit
Last active September 9, 2022 01:07
Useful git commands I will not remember.
Following some XCode-git freakyness.
making sure deleted files are infact removed.
git branch -d "dev 2"
git status | sed -n '/^# *deleted:/s///p' | xargs git rm
git add -u
//
// ComparingApproaches.swift
// NotificationTasks
//
// Created by carlynorama on 9/15/22.
//
//
// https://www.donnywals.com/comparing-lifecycle-management-for-async-sequences-and-publishers/ (code appraoch has been depricated since written)
// https://www.hackingwithswift.com/quick-start/concurrency/how-to-create-a-custom-asyncsequence
@carlynorama
carlynorama / -SpaceReservingResultLayout.swift
Created September 3, 2022 13:39
Picker will reserve the requested amount of space embedded in a form or popover. Uses the Layout Protocol
//
// ReservingSpaceLayout.swift
// LayoutTests
//
// Created by carlynorama on 8/28/22.
//
import SwiftUI
@carlynorama
carlynorama / PDF_CGContext_Response.md
Last active August 24, 2022 17:34
Forum post response I wrote with sample code of how to save and draw to screen PDF data made from scratch. Saved here for my reference.