Skip to content

Instantly share code, notes, and snippets.

@julianjames
Last active August 29, 2015 14:20
Show Gist options
  • Save julianjames/db418fb073a0ca3295cb to your computer and use it in GitHub Desktop.
Save julianjames/db418fb073a0ca3295cb to your computer and use it in GitHub Desktop.
//
// InterfaceController.swift
// Hackaball WatchKit Extension
//
// Created by Julian James on 29/04/2015.
// Copyright (c) 2015 Made by Many. All rights reserved.
//
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
@IBOutlet weak var connectionLabel : WKInterfaceLabel!
@IBOutlet weak var gameListTable : WKInterfaceTable!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Configure interface objects here.
let parentValues = [ "Watch" : "Info" ]
WKInterfaceController.openParentApplication (parentValues, reply: { (replyValues, error) -> Void in
// Show ball state
var state = replyValues["Ball State"] as! String
if state == "Connected!"
{
self.connectionLabel.setTextColor(UIColor.greenColor())
}
else
{
self.connectionLabel.setTextColor(UIColor.redColor())
}
self.connectionLabel.setText((state))
// List current games available
var gameDetails = replyValues["Games"] as! NSArray
self.gameListTable.setNumberOfRows(gameDetails.count, withRowType: "GAME")
gameDetails.enumerateObjectsUsingBlock ( { object, index, stop in
let gameRow = self.gameListTable.rowControllerAtIndex(index) as! TableRowController
gameRow.rowLabel.setText(object["name"] as? String)
})
})
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment