Skip to content

Instantly share code, notes, and snippets.

View jonreid's full-sized avatar

Jon Reid jonreid

View GitHub Profile
@jonreid
jonreid / main.swift
Created January 1, 2024 19:54
Step 1, an explicit main entry point that loads AppDelegate per https://qualitycoding.org/ios-app-delegate-testing/
import UIKit
let appDelegateClass = AppDelegate.self
UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(appDelegateClass))
import UIKit
@objc(TestingAppDelegate)
class TestingAppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func applicationDidFinishLaunching(_ application: UIApplication) {
window = nil
}
}
@jonreid
jonreid / main.swift
Last active January 1, 2024 21:50
Step 2, change appDelegateClass dynamically per https://qualitycoding.org/ios-app-delegate-testing/
import UIKit
let appDelegateClass: AnyClass = NSClassFromString("TestingAppDelegate") ?? AppDelegate.self
UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(appDelegateClass))
@jonreid
jonreid / gist:1283431
Created October 13, 2011 05:01
Test using OCHamcrest 1.6 hasProperty matcher
- (void)testArrayFromURLStringArray
{
// given
NSArray *URLStrings = [NSArray arrayWithObjects:@"one", @"two", nil];
// when
NSMutableArray *downloads = [MyDownloader arrayFromURLStringArray:URLStrings];
// then
assertThat(downloads, contains(hasProperty(@"URLString", @"one"),
@jonreid
jonreid / gist:1283418
Created October 13, 2011 04:52
Test before OCHamcrest 1.6
- (void)testArrayFromURLStringArray
{
// given
NSArray *URLStrings = [NSArray arrayWithObjects:@"one", @"two", nil];
// when
NSMutableArray *downloads = [MyDownloader arrayFromURLStringArray:URLStrings];
// then
assertThat(downloads, hasCountOf(2));
@jonreid
jonreid / gist:1258076
Last active November 26, 2020 11:09
Terminal command to help you find preprocessor code smells in Objective-C code
find . \( \( -name "*.[chm]" -o -name "*.mm" \) -o -name "*.cpp" \) -print0 | xargs -0 egrep -n '^\w*\#' | egrep -v '(import|pragma|else|endif|HC_SHORTHAND|MOCKITO_SHORTHAND)'