Skip to content

Instantly share code, notes, and snippets.

@yannxou
yannxou / XCUIElementQuery+matchingPredicate.swift
Created December 11, 2024 08:51
XCUIElementQuery Matching Extension
// Source: https://medium.com/@anthony.prokuda/how-to-locate-and-wait-for-an-element-in-xcuitest-a-powerful-approach-105b81628986
extension NSPredicate {
static func keyPath<T, U>(
_ keyPath: KeyPath<T, U>,
is type: NSComparisonPredicate.Operator = .equalTo,
value: U,
modifier: NSComparisonPredicate.Modifier = .direct,
options: NSComparisonPredicate.Options = []
) -> NSPredicate {
@yannxou
yannxou / XCUIElement+waitPredicate.swift
Created December 11, 2024 08:48
Waiting for XCUIElement attributes
// Source: https://medium.com/@anthony.prokuda/how-to-locate-and-wait-for-an-element-in-xcuitest-a-powerful-approach-105b81628986
extension XCUIElement {
func wait<U>(
attribute keyPath: KeyPath<XCUIElement, U>,
is comparisonOperator: NSComparisonPredicate.Operator,
value: U,
timeout: TimeInterval = 10
) -> XCUIElement? {
@yannxou
yannxou / Publisher+expect.swift
Created November 28, 2024 14:38
Publisher+expect
import Combine
import Foundation
enum PublisherExpectationError: Error {
case failedWithError(Error)
case finishedWithoutMatchingValue
case timedOut
}
public extension Publisher {
@yannxou
yannxou / publisher-expect.swift
Last active November 28, 2024 08:18
Publisher value expectation for swift-testing
import Combine
import Foundation
public extension Publisher {
func expect(performing action: @escaping () async -> Void, fulfills condition: @escaping (Output) -> Bool, timeout: TimeInterval) async -> Bool {
let publisher = self
.handleEvents(receiveSubscription: { _ in
Task {
await action()
@yannxou
yannxou / UserConfiguration.txt
Created August 12, 2024 13:06
Ableton Live Reface CP MIDI Control
# ======================================================
# Config File for User-defined InstantMappings
# ======================================================
[Globals]
# The primary MIDI channel that the controller uses in
# the range of 0-15.
GlobalChannel: 0
InputName: reface CP
OutputName: reface CP
@yannxou
yannxou / CopyFileStorageContent.sh
Last active July 16, 2024 08:37
Xcode build phase pre-action to copy File.app content for UI testing
# Ensure simulator is started before copying to grant access to folder (otherwise the target path remains read-only)
echo "Starting simulator (UUID=$TARGET_DEVICE_IDENTIFIER)..."
xcrun simctl boot $TARGET_DEVICE_IDENTIFIER; open -a Simulator
xcrun simctl bootstatus $TARGET_DEVICE_IDENTIFIER
FILES_PATH="$(xcrun simctl listapps $TARGET_DEVICE_IDENTIFIER | grep LocalStorage | awk -F'"' '{print $4}' | sed -e "s/^file:\/\///")/File Provider Storage"
INPUT_FOLDER="$SRCROOT/E2ETests/Resources/File Provider Storage";
echo "Copying File Provider Storage files to simulator...";
# Using rsync to skip copying hidden files
@yannxou
yannxou / Loggerformatting.swift
Created June 7, 2024 10:17
Xcode Logger formatting with optional parameters
// https://developer.apple.com/wwdc20/10168
let statisticsLogger = Logger (subsystem: "com.example.Fruta", category: "statistics")
// Log statistics about communication with a server.
func logStatistics(taskID: UUID, giftCardID: String, serverID: Int, seconds: Double) {
statisticsLogger.log("\(taskID) \(giftCardID, align: .left(columns: GiftCard.maxIDLength)) \(serverID) \(seconds, format: .fixed(precision: 2))")
@yannxou
yannxou / DebugLoggerOnly.swift
Created June 7, 2024 09:54
xcode disable logging in production
func customLog(_ category: String) -> OSLog {
#if DEBUG
return OSLog(subsystem: Bundle.main.bundleIdentifier!, category: category)
#else
return OSLog.disabled
#endif
}
@yannxou
yannxou / zalgo.swift
Created May 21, 2024 09:51
Zalgo text generator
// Zalgo text: https://en.wikipedia.org/wiki/Zalgo_text
func zalgo(_ string: String, intensity: Int = 5) -> String {
let combiningDiacriticMarks = 0x0300...0x036f
let latinAlphabetUppercase = 0x0041...0x005a
let latinAlphabetLowercase = 0x0061...0x007a
var output: [UnicodeScalar] = []
for scalar in string.unicodeScalars {
output.append(scalar)
guard (latinAlphabetUppercase).contains(numericCast(scalar.value)) ||
# Safely clean up SwiftUI Preview data located in:
# ~/Library/Developer/Xcode/UserData/Previews
xcrun simctl --set previews delete all