Skip to content

Commit

Permalink
use emoji objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigod committed Mar 10, 2018
1 parent 976edc1 commit 9a37eff
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 16 deletions.
4 changes: 4 additions & 0 deletions EmojiDictionary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
43A0CE972043A4C600139580 /* EmojiDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A0CE962043A4C600139580 /* EmojiDictionaryTests.swift */; };
43A0CEA22043A4C600139580 /* EmojiDictionaryUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A0CEA12043A4C600139580 /* EmojiDictionaryUITests.swift */; };
43A0CEB0204659FF00139580 /* DefinitionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A0CEAF204659FF00139580 /* DefinitionViewController.swift */; };
43A0CEB22048638200139580 /* Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A0CEB12048638200139580 /* Emoji.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -49,6 +50,7 @@
43A0CEA12043A4C600139580 /* EmojiDictionaryUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiDictionaryUITests.swift; sourceTree = "<group>"; };
43A0CEA32043A4C600139580 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
43A0CEAF204659FF00139580 /* DefinitionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefinitionViewController.swift; sourceTree = "<group>"; };
43A0CEB12048638200139580 /* Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Emoji.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -102,6 +104,7 @@
43A0CE812043A4C600139580 /* AppDelegate.swift */,
43A0CE832043A4C600139580 /* ViewController.swift */,
43A0CEAF204659FF00139580 /* DefinitionViewController.swift */,
43A0CEB12048638200139580 /* Emoji.swift */,
43A0CE852043A4C600139580 /* Main.storyboard */,
43A0CE882043A4C600139580 /* Assets.xcassets */,
43A0CE8A2043A4C600139580 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -264,6 +267,7 @@
files = (
43A0CE842043A4C600139580 /* ViewController.swift in Sources */,
43A0CEB0204659FF00139580 /* DefinitionViewController.swift in Sources */,
43A0CEB22048638200139580 /* Emoji.swift in Sources */,
43A0CE822043A4C600139580 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
18 changes: 18 additions & 0 deletions EmojiDictionary/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,37 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Category: Smile" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0bL-b0-Hop">
<rect key="frame" x="126.5" y="404" width="122" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Origin Year: 1992" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mep-4c-aJM">
<rect key="frame" x="121.5" y="445" width="132" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="mep-4c-aJM" firstAttribute="centerX" secondItem="hza-kP-sh0" secondAttribute="centerX" id="1tq-Ej-hIt"/>
<constraint firstItem="shd-pt-UaX" firstAttribute="centerX" secondItem="hza-kP-sh0" secondAttribute="centerX" id="Gec-qj-Exk"/>
<constraint firstItem="0bL-b0-Hop" firstAttribute="centerX" secondItem="hza-kP-sh0" secondAttribute="centerX" id="QRf-YH-A7O"/>
<constraint firstItem="pYP-sW-brf" firstAttribute="centerX" secondItem="hza-kP-sh0" secondAttribute="centerX" id="Uyv-d9-eYo"/>
<constraint firstItem="0bL-b0-Hop" firstAttribute="top" secondItem="pYP-sW-brf" secondAttribute="bottom" constant="20" id="c6p-9x-SzD"/>
<constraint firstItem="shd-pt-UaX" firstAttribute="top" secondItem="oMA-fr-i5c" secondAttribute="top" constant="40" id="dcr-kv-YCI"/>
<constraint firstItem="mep-4c-aJM" firstAttribute="top" secondItem="0bL-b0-Hop" secondAttribute="bottom" constant="20" id="tgl-Yk-paM"/>
<constraint firstItem="pYP-sW-brf" firstAttribute="top" secondItem="shd-pt-UaX" secondAttribute="bottom" constant="20" id="w1q-it-ooy"/>
</constraints>
<viewLayoutGuide key="safeArea" id="oMA-fr-i5c"/>
</view>
<connections>
<outlet property="categoryLabel" destination="0bL-b0-Hop" id="vSI-Wf-ts9"/>
<outlet property="emojiDescriptionLabel" destination="pYP-sW-brf" id="dz3-jE-LFx"/>
<outlet property="emojiLabel" destination="shd-pt-UaX" id="qcu-Wr-F5G"/>
<outlet property="originYear" destination="mep-4c-aJM" id="LO6-1m-Ncr"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="9IM-vT-Pa8" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
20 changes: 8 additions & 12 deletions EmojiDictionary/DefinitionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ import UIKit

class DefinitionViewController: UIViewController {

var emoji = "NO EMOJI!"
var emoji = Emoji()

@IBOutlet weak var emojiDescriptionLabel: UILabel!
@IBOutlet weak var emojiLabel: UILabel!
@IBOutlet weak var categoryLabel: UILabel!
@IBOutlet weak var originYear: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
emojiLabel.text = emoji

if emoji == "😘" {
emojiDescriptionLabel.text = "Kiss"
} else if emoji == "🤪" {
emojiDescriptionLabel.text = "Goofy face"
} else if emoji == "🤩" {
emojiDescriptionLabel.text = "upside down"
} else {
emojiDescriptionLabel.text = "NA"
}
emojiLabel.text = emoji.theEmoji
originYear.text = "Birth Year: \(emoji.originYear)"
categoryLabel.text = "Category: \(emoji.category)"
emojiDescriptionLabel.text = emoji.descritpion




Expand Down
15 changes: 15 additions & 0 deletions EmojiDictionary/Emoji.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Emoji.swift
// EmojiDictionary
//
// Created by Rodrigo Diaz on 3/1/18.
// Copyright © 2018 Rodrigo Diaz. All rights reserved.
//

class Emoji {
var theEmoji = ""
var category = ""
var descritpion = ""
var originYear = 0

}
39 changes: 35 additions & 4 deletions EmojiDictionary/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,56 @@ import UIKit
class ViewController: UIViewController, UITableViewDataSource,
UITableViewDelegate{

var emojis = ["😘", "🤪", "🤩", "😱", "💩"];
var emojis : [Emoji] = []

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return emojis.count;
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = emojis[indexPath.row]
cell.textLabel?.text = emojis[indexPath.row].theEmoji
return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
performSegue(withIdentifier: "moveSegue", sender: emojis[indexPath.row])
let emoji = emojis[indexPath.row]
performSegue(withIdentifier: "moveSegue", sender: emoji)
}

func makeEmojiList() -> [Emoji] {
let emoji1 = Emoji()
emoji1.theEmoji = "😘"
emoji1.category = "Face"
emoji1.descritpion = "Kiss"
emoji1.originYear = 2005

let emoji2 = Emoji()
emoji2.theEmoji = "🤪"
emoji2.category = "Face"
emoji2.descritpion = "Goofy"
emoji2.originYear = 2006

let emoji3 = Emoji()
emoji3.theEmoji = "🤩"
emoji3.category = "Face"
emoji3.descritpion = "Upside down"
emoji3.originYear = 2007

let emoji4 = Emoji()
emoji4.theEmoji = "😱"
emoji4.category = "Face"
emoji4.descritpion = "Fear"
emoji4.originYear = 2008

return [emoji1, emoji2, emoji3, emoji4]

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let defVC = segue.destination as! DefinitionViewController
defVC.emoji = sender as! String
defVC.emoji = sender as! Emoji
print(sender!)
}

Expand All @@ -42,6 +72,7 @@ UITableViewDelegate{
// Do any additional setup after loading the view, typically from a nib.
emojiTable.dataSource = self
emojiTable.delegate = self
emojis = makeEmojiList()
}

override func didReceiveMemoryWarning() {
Expand Down

0 comments on commit 9a37eff

Please sign in to comment.