• Online, Self-Paced
Course Description

Defensive Programming in iOS has to do with using coding practices and techniques to create apps, that are reliable, resilient, and easily testable. This course will teach you about thinking defensively in your approach to errors and exception handling, and also how to create automated tests for iOS apps.

Learning Objectives

Working with Errors

  • start the course
  • use error information returned indirectly from methods
  • test for specific kinds of errors based on domains and codes
  • create and return error objects from custom methods
  • use alert views to inform end users of error information
  • use an underlying error object to find out more detail about an error that has occurred

Working with Exceptions

  • create and throw/raise exceptions in iOS apps
  • catch and handle exceptions in iOS apps
  • use the @finally directive to guarantee code execution
  • convert a raised exception to an error when appropriate
  • capture and handle specific types of exceptions locally

Automated Unit Testing

  • create an XCTestCase Class using Xcode and Objective-C
  • create an XCTestCase Class using Xcode and Swift
  • create, execute, and check results of unit tests using Xcode and Objective-C
  • creating and executing unit tests in Swift
  • unit test private methods in custom classes
  • how to create tests that measure execution time of code
  • create and execute asynchronous tests

Automated UI Testing

  • recognize how to initiate the creation of an automated test of an iOS app
  • access interface elements by navigating the element hierarchy
  • use accessibility labels to interact with iOS app elements when automation testing
  • select and tap interface elements in automation testing
  • define pass and fail benchmarks for automation testing
  • use the logElementTree method to understand an app's view hierarchy
  • import previously created automation scripts for reuse


  • create assertions using NSAssert
  • create assertions using the assert function
  • create assertions in Swift

Practice: Errors and Exceptions

  • work with creating and managing errors and exceptions

Framework Connections

The materials within this course focus on the NICE Framework Task, Knowledge, and Skill statements identified within the indicated NICE Framework component(s):

Specialty Areas

  • Software Development