iOS Development


Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

What is a REPL?

  • Interactive language interpreter
  • Typically run in Terminal
  • Examples:
    • bash shell
    • python python
    • ruby irb
  • Characteristic of dynamic programming languages

REPL (Read-Eval-Print-Loop)

  1. Read Read the input from the user and parse it
  2. Eval Evaluate the parsed input
  3. Print Output the result of the evaluation
  4. Loop Start back at Read

Role of REPL in Swift

  • Good way to experiment with the swift syntax, especially of fundamental types
  • Great way to debug
  • Similar to use in playgrounds

Accessing Swift REPL

Terminal commands to start Swift REPL: * xcrun swift -sdk /Applications/ * Suggestion: Put the following alias in your .profile file: alias swift='xcrun swift -sdk /Applications/' * One Step from Terminal: echo "alias swift='xcrun swift -sdk /Applications/'" >> ~/.profile * Note: Will have to start another terminal session, or enter the following (only the first time): source ~/.profile

Round-Trip REPL Session

Start (if setup as above):

  • swift


  • :q
  • :quit
  • .exit
  • CTRL-D

REPL Session

  • Perform the following first if you want to access parts of the iOS SDK

import Foundation

Swift Scripts