Skip to content

Instantly share code, notes, and snippets.

View PaulWoodIII's full-sized avatar

Paul Wood III PaulWoodIII

View GitHub Profile
//: [Previous](@previous)
import SwiftUI
import PlaygroundSupport
struct ExampleView: View {
@ObservedObject var fetcher: ImageFetcher
init(fetcher: ImageFetcher) {
self.fetcher = fetcher
@PaulWoodIII
PaulWoodIII / PillTextView.swift
Created August 7, 2019 17:00
a button displayed as a pill
//: [Previous](@previous)
import SwiftUI
import PlaygroundSupport
struct PillTextView<U>: View where U : StringProtocol{
let action: () -> ()
let label: U
@PaulWoodIII
PaulWoodIII / DreamFetchedResultsSyntax.swift
Created August 7, 2019 14:36
Part of a Feedback to apple on what I want from the new FetchRequest struct in SwiftUI
@Environment(\.managedObjectContext) var managedObjectContext
@State var year = "1880"
@State var ascending = true
@State var someValue = "value"
@FetchRequest(
entity: YearOfBirth.entity(),
sortDescriptors: [NSSortDescriptor(key: "year", ascending: ascending.wrappedValue)],
predicate: NSPredicate(format: "%K = %@", “someAttributeKey”, someValue.wrappedValue)
) var years: FetchedResults<YearOfBirth>
@PaulWoodIII
PaulWoodIII / FetchedResultWidget.swift
Last active January 7, 2022 11:36
FetchRequest generation when sort state is changed
import SwiftUI
import CoreData
import Combine
struct NamesByYearView: View {
@EnvironmentObject var coreDataStack: CoreDataStack
@Environment(\.managedObjectContext) var managedObjectContext
@EnvironmentObject var importer: NameDatabaseImporter
@PaulWoodIII
PaulWoodIII / NamesByYearView+FetchedResultContainer.swift
Created August 6, 2019 15:03
right to the edge of where I think things should work I get a EXC_BAD
//
// NamesByYearView.swift
// NameList
//
// Created by Paul Wood on 7/31/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
import CoreData
@PaulWoodIII
PaulWoodIII / NamesByYearView.swift
Created August 6, 2019 13:46
creating a FetchRequest property based on state passed to a view
//
// NamesByYearView.swift
// NameList
//
// Created by Paul Wood on 7/31/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
import CoreData
@PaulWoodIII
PaulWoodIII / New Property Wrapper Syntax.swift
Created August 5, 2019 11:47
Some new APIs are available to us in SwiftUI dealing with Core Data
@Environment(\.managedObjectContext) var managedObjectContext
@FetchRequest(fetchRequest: YearOfBirth.allFetchRequest()) var years: FetchedResults<YearOfBirth>
@PaulWoodIII
PaulWoodIII / BreakingSwiftUIList.swift
Created August 5, 2019 01:11
It isn't hard to find some numbers that will cause SwiftUI to break down a little
struct Item: View, Identifiable {
let forInt: Int
var id: String {
return "\(forInt)"
}
var body : some View {
//: Make this view more complex
HStack{
Text("\(forInt)")
}
@PaulWoodIII
PaulWoodIII / ListOfAnimals.swift
Created August 4, 2019 13:26
How to solve rendering a Heterogeneous collection when you are required to use a Homogeneous List of Objects in SwiftUI, In short use a Wrapper / Box around the content
//
// ListOfAnimals.swift
// AnimalList
//
// Created by Paul Wood on 8/4/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
@PaulWoodIII
PaulWoodIII / NameHolder_Generic.swift
Created August 4, 2019 00:02
A sneaky addition, we can use generics to help us write this initializer for all types of Nameable
struct NameHolder: Nameable {
var id: String { return name }
var name: String
init<U>(nameable name: U) where U: Nameable {
self.name = name.name
}
}