Skip to content

Instantly share code, notes, and snippets.

View KingOfBrian's full-sized avatar

Brian King KingOfBrian

  • Boston Massachusetts
View GitHub Profile
@KingOfBrian
KingOfBrian / PublicationCenter.swift
Last active February 4, 2022 11:49
PublicationCenter
//
// PublicationCenter.swift
//
// Created by Brian King on 5/17/16.
// Copyright © 2016 Raizlabs. All rights reserved.
//
import Foundation
/// PublicationCenter is an NSNotificationCenter style object that
@KingOfBrian
KingOfBrian / XCTestAndNil.md
Last active January 8, 2024 19:34
XCTest and nil assertions

XCTest and Optional Unwrapping

XCTest is the default test harness on iOS an Apple’s other platforms. It provides support for organizing test cases and asserting expectations in your application code, and reporting the status of those expectations. It's not as fancy as some of the BDD frameworks like Quick and Cedar, but it has gotten much better than it used to be, and is my preferred test framework these days.

The Problem

One place where the XCTest assertion utilities fall a bit short has been with managing Optional variables in swift. The default use of XCTAssertNotNil don't provide any mechanism for unwrapping, easily leading to assertion checks like this:

class TestCaseDefault: XCTestCase {