Skip to content

Instantly share code, notes, and snippets.

View analogpotato's full-sized avatar
🎧
Working remote and loving it

Frank Foster analogpotato

🎧
Working remote and loving it
View GitHub Profile
@analogpotato
analogpotato / gist:6d4ca4733b343aa665de471a56cb43d9
Created February 18, 2022 01:24
Function returning the first non-iterative value from an array
import Foundation
var array = [1,2,1,3,5]
func arrayCalculation(_ array: [Int]) -> Int {
var dictionary: [Int:Int] = [:]
var sortedArray: [Int] = []
// With this portion of the code, I'm iterating over the array and adding the dictionary items to an array
VStack {
TabView {
//Add Group {} here for vertical method. be sure to add .rotationEffect(Angle(degrees: -90)) at the end of the Group closure
ForEach(data) { item in
CustomCell(data: item)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))
// Add .rotationEffect(Angle(degrees: 90)) as well for vertical implementation
@analogpotato
analogpotato / gist:28fd835a3cf9c172f655ad3d14a5b960
Created July 28, 2021 06:12
CollectionView horizontal scrolling example
//
//
//Here is the programmatic setup for the CollectionView
//
//
let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal //Change this to vertical
layout.minimumLineSpacing = 8 //Spacing here is not necessary, but adds a better inset for horizontal scrolling. Gives you a tiny peek of the background. Probably not great for vertical
// The issue I'm running into is that I'm adding D6DiceViews to an array and then
// attempting to randomly change the number on each die
//Here is the struct for the D6DiceView, it contains the function for the random roll (this is the full current view)
struct D6DiceView: View {
@Binding var rolledValue: String
@analogpotato
analogpotato / gist:c47794e9a6a7f12a51b71bf3bee6b3cf
Created July 10, 2020 23:12
Using UIViewRepresentable to declare a UIKit Menu from a button
//In your view, declare a UIViewRepresentable as a UIButton type as seen below.
//This is important as you cannot do it as a UIBarButtonItem (at least as I've found in Xcode 12 beta 2).
struct MenuButtonView: UIViewRepresentable {
typealias UIViewType = UIButton
let saveAction = UIAction(title: "") { action in }
let saveMenu = UIMenu(title: "", children: [