Skip to content

Instantly share code, notes, and snippets.

View ccwasden's full-sized avatar

Chase Wasden ccwasden

View GitHub Profile
struct NumberField<T: Numeric & LosslessStringConvertible>: View {
let prompt: String
@Binding var value: T?
@StateObject var viewModel = ViewModel()
class ViewModel: ObservableObject {
@Published var text = ""
var ignoreNextChange = false
@ccwasden
ccwasden / Await+Threading.swift
Created April 27, 2020 22:39
Await+Threading
//
// Author: Chase Wasden
// Website: https://gist.github.com/ccwasden
// Licensed under MIT license https://opensource.org/licenses/MIT
//
import Foundation
import Combine
// Threading
@ccwasden
ccwasden / Multiselect.swift
Created April 7, 2020 17:45
SwiftUI Multiselect
//
// Author: Chase Wasden
// Website: https://gist.github.com/ccwasden
// Licensed under MIT license https://opensource.org/licenses/MIT
//
import SwiftUI
struct Fruit: Selectable {
let name: String
@ccwasden
ccwasden / Multiselect2.swift
Last active April 29, 2020 11:56
Swift multiselect
//
// Author: Chase Wasden
// Website: https://gist.github.com/ccwasden
// Licensed under MIT license https://opensource.org/licenses/MIT
//
import SwiftUI
struct Fruit: Selectable {
let name: String
@ccwasden
ccwasden / Multiselect3.swift
Last active April 7, 2020 18:11
Multiselect using a custom property wrapper - Modified from child view through a Binding
//
// Author: Chase Wasden
// Website: https://gist.github.com/ccwasden
// Licensed under MIT license https://opensource.org/licenses/MIT
//
import SwiftUI
struct Fruit: Identifiable {
let name: String
@ccwasden
ccwasden / SwiftUI-MultiSelect.swift
Last active April 7, 2020 13:58
Multiselect using ObservableObject with child array - Modified from child view through a Binding
struct Cheese: Identifiable {
let name: String
var isSelected: Bool
var id: String { name }
}
class ViewModel: ObservableObject {
@Published var cheeses = [
Cheese(name: "Brie", isSelected: false),
Cheese(name: "Cheddar", isSelected: true),
@ccwasden
ccwasden / WithPopover.swift
Created February 5, 2020 13:39
Custom size popover in iOS SwiftUI
// -- Usage
struct Content: View {
@State var open = false
@State var popoverSize = CGSize(width: 300, height: 300)
var body: some View {
WithPopover(
showPopover: $open,
popoverSize: popoverSize,
@ccwasden
ccwasden / automateSandboxTesterEntry.js
Last active October 3, 2018 14:12
Automate rapid/fast creation of sandbox testers in itunesConnect
// Steps to use:
// 1. Go to itunesConnect > Users & Roles
// 2. Select "Testers" under the "Sandbox" header on the left
// 2. Open the console on your browser (eg. CMD-OPT-J)
// 3. Paste the code below (modified to your liking) into the console and hit enter
// 4. enter `createUser('desiredEmailAlias')` into the console and watch the user get created automatically
//
// NOTE: To create several users rapidly: in the console hit the up arrow, change the alias, and hit enter again. Repeat.
// Edit the user here to your liking
@ccwasden
ccwasden / ArrayUtils.swift
Created January 31, 2015 15:49
Some generic array utilities I use
func unwrapAndCollapse<T>(array:[T?]) -> [T] {
return array.reduce([]) { $1 != nil ? $0 + [$1!] : $0 }
}
func appendReplacingMatches<T>(first:[T], second:[T], matcher:((T,T)->Bool)) -> [T] {
var i = 0
var finalArray = first
var appendArray = second
while i < first.count && appendArray.count > 0 {
let item = appendArray.first!