Skip to content

Instantly share code, notes, and snippets.

View chrisvasselli's full-sized avatar

Chris Vasselli chrisvasselli

View GitHub Profile
set -o pipefail && xcodebuild -workspace StudyJapanese.xcworkspace -scheme "StudyJapanese" -testPlan "AllUITests" -sdk "$SIMULATOR_SDK" $destinations -derivedDataPath "build/DerivedData" -parallel-testing-enabled YES -parallel-testing-worker-count $parallel_test_workers -retry-tests-on-failure -test-iterations 2 test -resultBundlePath artifacts/TestResults.xcresult OS_ACTIVITY_MODE='disable' $exclude_non_parallelizable_tests_args | tee artifacts/xcodebuild.log | bundle exec xcpretty || true
# Tests than failed the first time and succeeded the second time will show up in both files. Need the ones that only failed.
testRefsID=$(xcrun xcresulttool get --format json --path artifacts/TestResults.xcresult | jq --raw-output '.actions._values[0].actionResult.testsRef.id._value')
xcrun xcresulttool get --format json --path artifacts/TestResults.xcresult --id $testRefsID | jq '.summaries._values[0].testableSummaries._values[0].tests._values[0].subtests._values[0].subtests._values[].subtests | select( . != null ) | ._v
@chrisvasselli
chrisvasselli / Error+Internet.swift
Created December 20, 2022 02:00
Check if an error is related to network conditions outside your control
extension Error {
var code: Int { return (self as NSError).code }
var domain: String { return (self as NSError).domain }
var userInfo: [String:Any] { return (self as NSError).userInfo }
var isRelatedToPoorInternetConnection: Bool {
switch self {
case URLError.timedOut,
URLError.cancelled,
URLError.dataNotAllowed,
extension Error {
var code: Int { return (self as NSError).code }
var domain: String { return (self as NSError).domain }
var userInfo: [String:Any] { return (self as NSError).userInfo }
func timeAfterWhichToRetry(retryCount: Int) -> TimeInterval? {
// CloudKit suggests us retry too often, so slow us down as we retry a lot, up to 5 minutes
if let suggestedTimeout = suggestedTimeAfterWhichToRetry {
if suggestedTimeAfterWhichToRetry == 0 {
return 0
import Foundation
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
@chrisvasselli
chrisvasselli / UITableView+Screenshots.swift
Created September 14, 2021 00:38
Create full page screenshots from a table view controller
import Foundation
import UIKit
extension UITableViewController: UIScreenshotServiceDelegate {
public func screenshotService(_ screenshotService: UIScreenshotService, generatePDFRepresentationWithCompletion completionHandler: @escaping (Data?, Int, CGRect) -> Void) {
let originalFrame = tableView.frame
let originalContentOffset = tableView.contentOffset
// Layout into an extra large frame, to force the actual heights to be calculated for all rows with estimated heights
@chrisvasselli
chrisvasselli / glossary-lookup.sh
Last active October 1, 2021 14:10
Lookup translations of a word in Apple's glossaries
# Run from a folder containing a folder for each language you want to look up a word in,
# with the contents of the glossaries from https://developer.apple.com/download/more/?=glossaries
#
# Prints the all translations found for the given word in each language, along with how many occurrences of that translation were found.
#
# Dependencies
# brew install xmlstarlet
#
# Usage
#
public func XCTAssertSoon(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, waitTime: TimeInterval = 3) {
let startTime = Date()
repeat {
let success = (try? expression()) ?? false
if success {
return
}
else {
Thread.sleep(forTimeInterval: 1)
}