Skip to content

Instantly share code, notes, and snippets.

View benlmyers's full-sized avatar
😌
Making great things

Benjamin Myers benlmyers

😌
Making great things
View GitHub Profile
//
// Global.swift
// MVVM-SwiftUI
//
// Created by Ben Myers on 9/14/22.
//
import SwiftUI
class Global: ObservableObject {
//
// FoodView.swift
// MVVM-SwiftUI
//
// Created by Ben Myers on 9/13/22.
//
import SwiftUI
struct FoodView: View {
//
// FoodViewModel.swift
// MVVM-SwiftUI
//
// Created by Ben Myers on 9/13/22.
//
import SwiftUI
import Foundation
@benlmyers
benlmyers / ViewModel.swift
Created September 13, 2022 23:35
A simple protocol that defines a ViewModel for MVVM architecture. Requires a `Global` environment object used for dependency injection.
import SwiftUI
/**
A protocol for MVVM-architecture.
View models manage most (but not all) of a view's logic. When handling large amounts of logic related to a particular view or views, it's useful to have a view model to manage the logic.
View models act as the bridge between models and views in MVVM architecture.
# Example
//
// Food.swift
// MVVM-SwiftUI
//
// Created by Ben Myers on 9/13/22.
//
import Foundation
/**
#!/bin/bash
git=$(sh /etc/profile; which git)
number_of_commits=$("$git" rev-list HEAD --count)
git_release_version=$("$git" describe --tags --always --abbrev=0)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${git_release_version#*v}" "$INFOPLIST_FILE"
@benlmyers
benlmyers / SubsetPermutations.cpp
Created July 11, 2021 21:12
A c++ script that calculates all permutations of all subsets of a given list.
//
// main.cpp
// SubsetPermutations
//
// Created by Ben Myers on 7/11/21.
//
#include <iostream>
#include <cstring>
#include <vector>
@benlmyers
benlmyers / View.swift
Created June 22, 2021 23:42
A quick way to add together views using the + operator.
import SwiftUI
extension View {
static func + <T> (lhs: Self, rhs: T) -> some View where T: View {
HStack {
lhs
rhs
}
}
@benlmyers
benlmyers / PadKit.pde
Created March 3, 2020 14:35
PadKit for Processing. Use Processing with your Novation Launchpad MKII.
import themidibus.*;
import javax.sound.midi.MidiMessage;
MidiBus myBus;
PKColor padColor;
PKManager pm;
// PadKit, PKManager and all subclasses in this project are owned by Ben Myers.
// Project initated 11/19/2018
// Latest update 11/21/2018
// Current version 1.2