This gist accompanies a blog post on Masilotti.com, How to manage multiple sheets in SwiftUI.
class SidekiqPolicy | |
attr_reader :user, :environment | |
def initialize(user, environment: Rails.env) | |
@user = user | |
@environment = environment | |
end | |
def visible? | |
user.admin? || environment.development? |
enum HTTP { | |
struct Response<T> { | |
let value: T | |
let headers: [AnyHashable: Any] | |
} | |
enum HTTPError<T: LocalizedError>: LocalizedError { | |
case failedRequest | |
case invalidResponse | |
case invalidRequest(T) |
These three files show how to handle forms with (legacy) Turbolinks in your Rails app with the new Turbo Native adapters.
- The Rails controller renders the form partial with an
:unprocessable_entity
status when encountering a form validation error - The form is submitted via AJAX (
local: false
orremote: true
depending on your Rails version) - This is caught via the
ajax:error->form#onError
Stimulus action - The Stimulus controller replaces the form's contents with the server-sided rendered HTML
- The native app is informed when the redirect occurs on a succesful submission
// 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 |
class TestVisitDelegate: VisitDelegate { | |
func visitDidStart() { | |
record(#function) | |
} | |
func visitDidComplete() { | |
record(#function) | |
} | |
// MARK: Testing verification helpers. |
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.
ps aux | grep _sim | grep -v grep | awk '{print $2}' | xargs kill -9 2>/dev/null |
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)) | |
} |
This gist accompanies the blog post Building NSURL Queries with NSURLQueryItems and NSURLComponents.