Skip to content

Instantly share code, notes, and snippets.

View PaulWoodIII's full-sized avatar

Paul Wood III PaulWoodIII

View GitHub Profile
@PaulWoodIII
PaulWoodIII / SelectedItems+ItemIsAClass.swift
Created August 19, 2019 00:41
selected items are not selected if the Item type is a reference instead of a value as well
//
// SelectedItems.swift
// OrderedList
//
// Created by Paul Wood on 8/18/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
import Combine
@PaulWoodIII
PaulWoodIII / SelectedItems.swift
Created August 19, 2019 00:36
SwiftUI does not select items with this code
//
// SelectedItems.swift
// OrderedList
//
// Created by Paul Wood on 8/18/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
import Combine
@PaulWoodIII
PaulWoodIII / SelectedItems.swift
Created August 19, 2019 00:02
quick example of how to use selection in a SwiftUI list, an ObservableObject provides the content as well
//: [Previous](@previous)
import SwiftUI
import Combine
import PlaygroundSupport
class Context: ObservableObject {
@Published var selectedItems: Set<String>
@Published var items: Array<String>
@PaulWoodIII
PaulWoodIII / ChooserView.swift
Created August 18, 2019 23:58
a quick hack on selected items in a list via @zoejessica
//
// ContentView.swift
// OrderedList
//
// Created by Paul Wood on 8/18/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
import Combine
@PaulWoodIII
PaulWoodIII / TestPersistentContainer.swift
Created August 10, 2019 18:44
used in Xcode test on each unit test, loads fast, is in memory and doesn't affect other test so long as you don't test concurrently
/// Just a Holder for a persistentContainer that is lazily loaded
class TestPersistentContainer {
lazy var persistentContainer: NSPersistentContainer = {
let bundle = Bundle(for: CoreDataService.self)
let modelURL = bundle.url(forResource: CoreDataModelName, withExtension: "momd")!
let mom = NSManagedObjectModel(contentsOf: modelURL)!
let container = NSPersistentContainer(name: "LateralModel",
managedObjectModel: mom)
let description = container.persistentStoreDescriptions.first!
description.url = URL(fileURLWithPath: "/dev/null")
@PaulWoodIII
PaulWoodIII / OvercastStyleNowPlayingViewWatch.swift
Created August 9, 2019 19:42
My version of Overcast's Now playing view in SwiftUI
//
// ContentView.swift
// FakeOvercast WatchKit Extension
//
// Created by Paul Wood on 8/8/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
import SFSafeSymbols
@PaulWoodIII
PaulWoodIII / CurrentValueSubjectToBinding.swift
Last active January 9, 2024 01:20
Bindings over a CurrentValue subject allow you to use combine for side affects
//: [Previous](@previous)
import Foundation
import SwiftUI
import Combine
//: Current Value Subject is a value, a publisher and a subscriber all in one
let currentValueSubject = CurrentValueSubject<Bool, Never>(true)
print(currentValueSubject.value)
@PaulWoodIII
PaulWoodIII / PassingBindings.swift
Created August 8, 2019 12:50
There is more than one way to handle Bindings in your code, here's two ways I know how
import SwiftUI
import PlaygroundSupport
struct BoolHolder: View {
@State var boolProperty: Bool = false
var body: some View {
VStack{
if boolProperty {
@PaulWoodIII
PaulWoodIII / PhotoPickerDisplayer.swift
Created August 8, 2019 12:33
display a selected image using UIViewControllerRepresentable and bindings to a selected UIImage to pass information back to SwiftUI
//: [Previous](@previous)
import SwiftUI
import PlaygroundSupport
struct PhotoPickerDisplayer: View {
@State var presentation: Bool = false
@State var selectedImage: UIImage? = nil
@PaulWoodIII
PaulWoodIII / SiriShortcutsActionCard.swift
Last active August 7, 2019 23:31
I wonder if Ari wants to use SwiftUI in Shortcuts
//: [Previous](@previous)
import SwiftUI
import PlaygroundSupport
struct SiriShortcutsActionCard<U>: View where U : StringProtocol {
let action: () -> ()
let onMore:() -> ()
let iconImage: AnyView