Created
July 9, 2015 19:43
-
-
Save coderberry/32647f7aca026dbb33ba to your computer and use it in GitHub Desktop.
Example of using a switch statement instead of if/else statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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