Skip to content

Instantly share code, notes, and snippets.

@ChrisMash
ChrisMash / ut_verify_expected_values_poor.swift
Last active October 16, 2023 19:31
A UT that does a poor job of verifying expected values
delegate = ADelegate()
sut = UnitBeingTested(delegate)
sut.aFunctionCall()
verify(delegate)
.callMadeTo(functionOnDelegate)
.withParameter(anything())
@ChrisMash
ChrisMash / ProfileExpiryLogger.swift
Last active April 30, 2023 12:01
Example of updating an app's provisioning profile expiry time in a Firebase realtime database (gist for https://chris-mash.medium.com/using-provisioningprofile-and-firebase-to-monitor-profile-expiries-remotely-7832f475d7b7)
//
// Created by Chris Mash on 10/02/2022.
//
import UIKit
import ProvisioningProfile
import FirebaseDatabase
// NOTE: this gist uses some personal extensions I've written which aren't shared here but you should be able to swap out easily enough:
// Bundle.main.appVersion
struct ContentView: View {
private var gameState = GameState()
@Namespace private var animation
var body: some View {
VStack {
// Some simple instructions
Text("""
Tap a + button to add a card from the deck to the relevant hand.
struct DeckView: View {
@ObservedObject var deck: Hand
let namespace: Namespace.ID
var body: some View {
ZStack {
// Just need to draw the last two so that the transition of card
// from the hand back to the deck results in the old top card being
// rendered as the new top card animates in
// A view to represent the cards in a hand
struct HandView: View {
@ObservedObject var hand: Hand
let namespace: Namespace.ID
let onCardTap: (Card) -> Void
var body: some View {
HStack {
ForEach(hand.cards) { card in
struct CardView_Previews: PreviewProvider {
// Create a wrapper view that will let us hold a @Namespace to pass to the view
struct Wrapper: View {
@Namespace var animation
var body: some View {
CardView(card: Card(number: 1), namespace: animation)
.padding()
.background(Color.gray)
}
}
// A view to represent a single card
struct CardView: View {
let card: Card
let namespace: Namespace.ID
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 20,
style: .continuous)
// A representation of the current state of the game,
// including which cards each player has and the deck
// of cards that can be picked up from
class GameState {
private(set) var deck = Hand()
private(set) var hands = [Hand]()
init() {
// Fill the deck with 20 cards, shuffled
// A representation of a playing card
struct Card: Identifiable, Equatable {
let id = UUID()
let number: Int
}
// A representation of a player's hand of cards
class Hand: ObservableObject, Identifiable {
let id = UUID()
@Published var cards = [Card]()
@ChrisMash
ChrisMash / mailto.swift
Last active April 9, 2023 02:19
Send an email using the user's chosen default email app (e.g. Mail, Gmail, Outlook etc.) instead of using MFMailComposeViewController that requires the Mail app to be setup with an account
let address = "[email protected]"
let subject = "AwesomeApp Feedback"
// Example email body with useful info for bug reports
let body = "\n\nApp Version: \(appVersion)\nDevice: \(deviceType)\niOS: \(osVersion)"
// Build the URL from its components
var components = URLComponents()
components.scheme = "mailto"
components.path = address