Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save coderberry/32647f7aca026dbb33ba to your computer and use it in GitHub Desktop.
Save coderberry/32647f7aca026dbb33ba to your computer and use it in GitHub Desktop.
Example of using a switch statement instead of if/else statements
//
// EmojiDetailInterfaceController.swift
// Emojis
//
// Created by Eric Berry on 7/9/15.
// Copyright (c) 2015 Eric Berry. All rights reserved.
//
import WatchKit
import Foundation
class EmojiDetailInterfaceController: WKInterfaceController {
@IBOutlet weak var emojiLabel: WKInterfaceLabel!
@IBOutlet weak var emojiDescriptionLabel: WKInterfaceLabel!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
var emoji = context as! String
// Configure interface objects here.
self.emojiLabel.setText(emoji)
switch emoji {
case "๐Ÿ˜‚":
self.emojiDescriptionLabel.setText("Happy Cry")
case "๐Ÿ‘":
self.emojiDescriptionLabel.setText("Thumbs Up")
case "๐ŸŸ":
self.emojiDescriptionLabel.setText("Fries")
case "๐Ÿ‘™":
self.emojiDescriptionLabel.setText("Bikini")
case "๐Ÿ’Š":
self.emojiDescriptionLabel.setText("Pill")
case "๐Ÿ’ฉ":
self.emojiDescriptionLabel.setText("Pile of Poo")
case "๐Ÿ‘ฎ":
self.emojiDescriptionLabel.setText("Cop")
case "๐Ÿ‘ป":
self.emojiDescriptionLabel.setText("Ghost")
default:
self.emojiDescriptionLabel.setText("Huh!")
}
}
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