Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to latest version of Swift #6

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
25 changes: 24 additions & 1 deletion swift/Trivia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = "Legacy Coderetreat";
TargetAttributes = {
2D130ABB1BCDA46D0099E18F = {
Expand Down Expand Up @@ -199,13 +199,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
Expand All @@ -232,6 +242,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -243,13 +254,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
Expand All @@ -268,6 +289,8 @@
MACOSX_DEPLOYMENT_TARGET = 10.9;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
20 changes: 10 additions & 10 deletions swift/Trivia/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Foundation

public class Game {
var players = [String]()
var places = [Int](count: 6, repeatedValue: 0)
var purses = [Int](count: 6, repeatedValue: 0)
var inPenaltyBox = [Bool](count: 6, repeatedValue: false)
var places = [Int](repeating: 0, count: 6)
var purses = [Int](repeating: 0, count: 6)
var inPenaltyBox = [Bool](repeating: false, count: 6)

var popQuestions = [String]()
var scienceQuestions = [String]()
Expand All @@ -27,7 +27,7 @@ public class Game {
popQuestions.append("Pop Question \(i)")
scienceQuestions.append(("Science Question \(i)"))
sportsQuestions.append(("Sports Question \(i)"))
rockQuestions.append(createRockQuestion(i))
rockQuestions.append(createRockQuestion(index: i))
}
}

Expand Down Expand Up @@ -121,19 +121,19 @@ public class Game {
if inPenaltyBox[currentPlayer]{
if isGettingOutOfPenaltyBox {
print("Answer was correct!!!!")
purses[currentPlayer]++
purses[currentPlayer] += 1
print(players[currentPlayer],
"now has",
purses[currentPlayer],
"Gold Coins.")

let winner = didPlayerWin
currentPlayer++
currentPlayer += 1
if currentPlayer == players.count {currentPlayer = 0}

return winner
} else {
currentPlayer++
currentPlayer += 1
if currentPlayer == players.count {currentPlayer = 0}
return true
}
Expand All @@ -143,14 +143,14 @@ public class Game {
} else {

print("Answer was corrent!!!!")
purses[currentPlayer]++
purses[currentPlayer] += 1
print(players[currentPlayer],
"now has",
purses[currentPlayer],
"Gold Coins.")

let winner = didPlayerWin
currentPlayer++
currentPlayer += 1
if currentPlayer == players.count {currentPlayer = 0}

return winner
Expand All @@ -162,7 +162,7 @@ public class Game {
print(players[currentPlayer], "was sent to the penalty box")
inPenaltyBox[currentPlayer] = true

currentPlayer++
currentPlayer += 1
if currentPlayer == players.count {currentPlayer = 0}
return true
}
Expand Down
8 changes: 4 additions & 4 deletions swift/Trivia/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ var notAWinner: Bool

let aGame = Game()

aGame.add("Chet")
aGame.add("Pat")
aGame.add("Sue")
_ = aGame.add(playerName: "Chet")
_ = aGame.add(playerName: "Pat")
_ = aGame.add(playerName: "Sue")

repeat {

aGame.roll(Int(arc4random_uniform(5)) + 1)
aGame.roll(roll: Int(arc4random_uniform(5)) + 1)

if (Int(arc4random_uniform(9)) == 7) {
notAWinner = aGame.wrongAnswer()
Expand Down