Skip to content

Instantly share code, notes, and snippets.

View joemasilotti's full-sized avatar
📱
Helping Rails developers build iOS and Android apps with Turbo Native.

Joe Masilotti joemasilotti

📱
Helping Rails developers build iOS and Android apps with Turbo Native.
View GitHub Profile
@joemasilotti
joemasilotti / ScriptMessageEnum.swift
Created February 10, 2021 14:59
Two approached to a Swift enum with associated type
// Enum with manual parsing.
enum ScriptMessage {
case registerForRemoteNotifications
case showBackButton(url: URL)
case signOutCompleted
init?(body: [String: Any]) {
switch body["name"] as? String {
case "registerForRemoteNotifications":
self = .registerForRemoteNotifications
@joemasilotti
joemasilotti / TestVisitDelegate.swift
Created December 28, 2020 18:44
Using #function to record messages sent to Swift test doubles
class TestVisitDelegate: VisitDelegate {
func visitDidStart() {
record(#function)
}
func visitDidComplete() {
record(#function)
}
// MARK: Testing verification helpers.
@joemasilotti
joemasilotti / .UI tests without UI Testing experiment.md
Last active December 6, 2020 13:46
UI tests without UI Testing experiment

UI tests without UI Testing experiment

This gist is a small experiment to see if there's an "in-between" for testing iOS applications. More feature-level than XCTest but not as heavy handed (or slow and brittle) as UI Testing.

The general idea is to provide an API similar to UI Testing but be able to spin up any controller on the fly. By putting the controller inside of a window the test behaves a bit more like the real app.

Currently, only two methods are explored: finding labels and buttons. An obvious omission is searching for the view recursively. A perhaps less obvious omission is still being able to tap disabled buttons.

This extends on my thoughts in a recent blog, Testing the UI without UI Testing in Swift.

@joemasilotti
joemasilotti / ContentView.swift
Last active August 4, 2020 19:27
SwiftUI List/ForEach with bindings
import SwiftUI
struct ContentView: View {
@ObservedObject private var signalStore = SignalStore()
var body: some View {
VStack {
List(signalStore.all) { signal in
SignalView(signal: self.signalStore.binded(signal: signal))
}
@joemasilotti
joemasilotti / Multiple sheets in SwiftUI.md
Last active October 13, 2021 03:20
Multiple sheets in SwiftUI
@joemasilotti
joemasilotti / Application.swift
Created February 28, 2020 17:45
Roll your own iOS dependency injection
protocol Injectable: class {
var router: Routable { get }
}
class Injector: Injectable {
lazy var router: Routable { Router() }()
}
protocol Routable {
func route(url: String)
@joemasilotti
joemasilotti / bootstrap4_breadcrumbs_builder.rb
Last active October 22, 2019 21:37 — forked from SaladFork/bootstrap4_breadcrumbs_builder.rb
`breadcrumbs_on_rails` builder with Bootstrap 4 compatible output
# `Bootstrap4BreadcrumbsBuilder `is a Bootstrap 4 (alpha6) compatible breadcrumb
# builder. It is designed to work with the `breadcrumbs_on_rails` gem as a
# drop-in builder replacement.
#
# Bootstrap4BreadcrumbsBuilder accepts a limited set of options:
#
# | option | default | description |
# | ---------------- | ------- | ------------------------------------------ |
# | `:container_tag` | `:ol` | What tag to use for the list container |
# | `:tag` | `:li` | What HTML tag to use for breadcrumb items |
@joemasilotti
joemasilotti / ..md
Last active September 13, 2022 14:20
Resetting NSUserDefaults in UI Testing

Resetting NSUserDefaults in UI Testing

  1. Add "UI-Testing" to launchArguments before launching the app under test
  2. On launch, check for the argument in AppDelegate.swift
  3. If it exists remove everything for the app's domain from NSUserDefaults
@joemasilotti
joemasilotti / Testing View Controllers in Swift 3.0
Last active September 10, 2017 22:39
Testing View Controllers in Swift 3.0
.
@joemasilotti
joemasilotti / AddressFormatter.swift
Created March 27, 2016 20:44
AddressFormatter in Swift
import CoreLocation
struct AddressFormatter {
private let placemark: Placemarkable
init(placemark: Placemarkable) {
self.placemark = placemark
}
func formattedAddress() -> String {