Skip to content
This repository has been archived by the owner on Jul 5, 2018. It is now read-only.

Update to Xcode 8.0 and Swift 3.0 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions SpaceAdventure/HelperFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Foundation
// Wait for the user to type something in the console, and return what
// they type as a String with the trailing newline character removed.
func getln() -> String {
let stdin = NSFileHandle.fileHandleWithStandardInput()
var input = NSString(data: stdin.availableData, encoding: NSUTF8StringEncoding)
input = input!.stringByTrimmingCharactersInSet(NSCharacterSet.newlineCharacterSet())
let stdin = FileHandle.withStandardInput
var input = NSString(data: stdin.availableData, encoding: String.Encoding.utf8)
input = input!.trimmingCharacters(in: CharacterSet.newlines)
return input as! String
}
12 changes: 6 additions & 6 deletions SpaceAdventure/SpaceAdventure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ class SpaceAdventure {
}
}

private func displayIntroduction() {
fileprivate func displayIntroduction() {
print("Welcome to the \(planetarySystem.name)!")
print("There are \(planetarySystem.planets.count) planets to explore.")
}

private func responseToPrompt(prompt: String) -> String {
fileprivate func responseToPrompt(_ prompt: String) -> String {
print(prompt)
return getln()
}

private func greetAdventurer() {
fileprivate func greetAdventurer() {
let name = responseToPrompt("What is your name?")
print("Nice to meet you, \(name). My name is Eliza, I'm an old friend of Siri.")
}

private func determineDestination() {
fileprivate func determineDestination() {
var decision = "" // Start with empty String
while !(decision == "Y" || decision == "N") {
decision = responseToPrompt("Shall I randomly choose a planet for you to visit? (Y or N)")
Expand All @@ -58,7 +58,7 @@ class SpaceAdventure {
}
}

private func visit(planetName: String) {
fileprivate func visit(_ planetName: String) {
print("Traveling to \(planetName)...")
for planet in planetarySystem.planets {
if planetName == planet.name {
Expand All @@ -67,4 +67,4 @@ class SpaceAdventure {
}
}

}
}