Skip to content

Instantly share code, notes, and snippets.

View PaulWoodIII's full-sized avatar

Paul Wood III PaulWoodIII

View GitHub Profile
@PaulWoodIII
PaulWoodIII / IdentifiableAlertView.swift
Created August 3, 2019 22:59
An example of a complex SwiftUI Alert view using and Identifiable binding
//: [Previous](@previous)
import SwiftUI
import PlaygroundSupport
enum AlertTypes: String, Identifiable {
case simple = "A Simple Alert"
case complex = "A Complex Alert"
@PaulWoodIII
PaulWoodIII / SimpleIdentifiableList.swift
Created August 3, 2019 23:19
A Simple list that uses the Identifiable protocol
import SwiftUI
import PlaygroundSupport
struct Name: Identifiable, ExpressibleByStringLiteral {
var name: String
public init(stringLiteral value: Swift.StringLiteralType) {
self.name = value
}
var id: String { return name }
}
@PaulWoodIII
PaulWoodIII / SwiftUI_List.swift
Created August 3, 2019 23:50
The Interface of List we are using
public struct List<SelectionValue, Content> : View where SelectionValue : Hashable, Content : View {
public init(selection: Binding<Set<SelectionValue>>?, @ViewBuilder content: () -> Content)
}
@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
}
}
@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 / 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 / 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 / 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 / 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 / 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