iOS Development

REPL

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

3460:489 iOS Development Fall 2014

What is a REPL?

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

Accessing Swift REPL

Terminal commands to start Swift REPL: * xcrun swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk * Suggestion: Put the following alias in your .profile file: alias swift='xcrun swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk' * One Step from Terminal: echo "alias swift='xcrun swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'" >> ~/.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):

Quit:

REPL Session

import Foundation

Swift Scripts