Skip to content

Commit

Permalink
Update Messages project for Xcode 8 release
Browse files Browse the repository at this point in the history
  • Loading branch information
samburnstone committed Oct 13, 2016
1 parent a99c222 commit 424baad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions 01 - Messages/Battleship/MessagesExtension/GameBoardView.swift
Expand Up @@ -17,9 +17,9 @@ class GameBoardView: UICollectionView {
case deselected
}

private var cellStyles = Array(repeating: CellStyle.deselected, count: 9)
fileprivate var cellStyles = Array(repeating: CellStyle.deselected, count: 9)

var onCellSelection: ((cellLocation: Int) -> Void)?
var onCellSelection: ((Int) -> Void)?

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand Down Expand Up @@ -81,12 +81,12 @@ extension GameBoardView {
decorate(cell, for: selectionStyle)
}

private func decorate(_ cell: UICollectionViewCell, for style: CellStyle) {
fileprivate func decorate(_ cell: UICollectionViewCell, for style: CellStyle) {
switch style {
case .selectedGreen:
cell.backgroundColor = .green()
cell.backgroundColor = .green
case .selectedRed:
cell.backgroundColor = .red()
cell.backgroundColor = .red
case .deselected:
cell.backgroundColor = UIColor(red:0.33, green:0.43, blue:0.54, alpha:1.00)
}
Expand All @@ -107,7 +107,7 @@ extension GameBoardView: UICollectionViewDataSource {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "GameCell", for: indexPath)

cell.layer.borderWidth = 5
cell.layer.borderColor = UIColor.black().withAlphaComponent(0.5).cgColor
cell.layer.borderColor = UIColor.black.withAlphaComponent(0.5).cgColor

decorate(cell, for: cellStyles[indexPath.row])

Expand All @@ -125,7 +125,7 @@ extension GameBoardView: UICollectionViewDelegateFlowLayout {
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
onCellSelection?(cellLocation: indexPath.row)
onCellSelection?(indexPath.row)
}
}

Expand Up @@ -21,7 +21,7 @@ class MessagesViewController: MSMessagesAppViewController {
}

extension MessagesViewController {
private func configureChildViewController(for presentationStyle: MSMessagesAppPresentationStyle,
fileprivate func configureChildViewController(for presentationStyle: MSMessagesAppPresentationStyle,
with conversation: MSConversation) {
// Remove any existing child view controllers
for child in childViewControllers {
Expand Down Expand Up @@ -61,7 +61,7 @@ extension MessagesViewController {
childViewController.didMove(toParentViewController: self)
}

private func createShipLocationViewController(with conversation: MSConversation) -> UIViewController {
fileprivate func createShipLocationViewController(with conversation: MSConversation) -> UIViewController {
guard let controller = storyboard?.instantiateViewController(withIdentifier: "ShipLocationViewController") as? ShipLocationViewController else {
fatalError("Cannot instantiate view controller")
}
Expand All @@ -81,7 +81,7 @@ extension MessagesViewController {
return controller
}

private func createShipDestroyViewController(with conversation: MSConversation, model: GameModel) -> UIViewController {
fileprivate func createShipDestroyViewController(with conversation: MSConversation, model: GameModel) -> UIViewController {
guard let controller = storyboard?.instantiateViewController(withIdentifier: "ShipDestroyViewController") as? ShipDestroyViewController else {
fatalError("Cannot instantiate view controller")
}
Expand All @@ -105,7 +105,7 @@ extension MessagesViewController {
return controller
}

private func createGameStartViewController() -> UIViewController {
fileprivate func createGameStartViewController() -> UIViewController {
guard let controller = storyboard?.instantiateViewController(withIdentifier: "GameStartViewController") as? GameStartViewController else {
fatalError("Cannot instantiate view controller")
}
Expand Down
Expand Up @@ -15,7 +15,7 @@ class ShipDestroyViewController: UIViewController {

var model: GameModel!

var onGameCompletion: ((model: GameModel, playerWon: Bool, snapshot: UIImage) -> Void)?
var onGameCompletion: ((GameModel, Bool, UIImage) -> Void)?

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -64,11 +64,11 @@ extension ShipDestroyViewController {

if incorrectAttemptsCount() >= GameConstants.incorrectAttemptsAllowed {
model.isComplete = true
onGameCompletion?(model: model, playerWon: false, snapshot: snapshot)
onGameCompletion?(model, false, snapshot)
}
else if shipsHitCount() == GameConstants.totalShipCount {
model.isComplete = true
onGameCompletion?(model: model, playerWon: true, snapshot: snapshot)
onGameCompletion?(model, true, snapshot)
}
}

Expand Down
Expand Up @@ -14,7 +14,7 @@ class ShipLocationViewController: UIViewController {
@IBOutlet weak var remainingLabel: UILabel!
@IBOutlet weak var finishedButton: UIButton!

var onLocationSelectionComplete: ((gameState: GameModel, snapshot: UIImage) -> Void)?
var onLocationSelectionComplete: ((GameModel, UIImage) -> Void)?

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -42,16 +42,16 @@ class ShipLocationViewController: UIViewController {
// Clear screen for snapshot (we don't want to give away where we've located our ships!)
gameBoard.reset()

onLocationSelectionComplete?(gameState: model, snapshot: UIImage.snapshot(from: gameBoard))
onLocationSelectionComplete?(model, UIImage.snapshot(from: gameBoard))
}
}

extension ShipLocationViewController {
private var shipsLeftToPosition: Int {
fileprivate var shipsLeftToPosition: Int {
return GameConstants.totalShipCount - self.gameBoard.selectedCells.count
}

private func updateLabels() {
fileprivate func updateLabels() {
remainingLabel.text = "Ships to Place: \(shipsLeftToPosition)"
finishedButton.isEnabled = shipsLeftToPosition == 0
}
Expand Down

0 comments on commit 424baad

Please sign in to comment.