/
beerScanningViewController.swift
80 lines (63 loc) · 2.25 KB
/
beerScanningViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// beerScanningViewController.swift
// sudsWithBuds
//
// Created by Seth Saperstein on 9/24/17.
// Copyright © 2017 Seth Saperstein. All rights reserved.
//
import UIKit
class beerScanningViewController: UIViewController, takingPhotoViewControllerDelegate {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toCamera" {
let nav = segue.destination as! takingPhotoViewController
nav.delegate = self
}
}
func giveCode(code: String) {
currentCode = code
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var currentCode : String? {
didSet {
if let name = barcodeLookup[currentCode!] {
Detection.text = name
beerImage.image = UIImage(named: name + ".png")
comment.text = "Drink successfully added!"
Singleton.sharedInstance.newPost = name
Singleton.sharedInstance.postAdded = true
}
else {
Detection.text = "Drink not found"
beerImage.image = nil
comment.text = "Scan again!"
}
}
}
@IBOutlet weak var comment: UILabel!
@IBOutlet weak var Detection: UILabel!
@IBOutlet weak var beerImage: UIImageView!
var barcodeLookup: [String : String] = [
"0070847811268" : "Monster Energy",
"0611269991000" : "Red Bull",
"049000001327" : "Sprite",
"012000809965" : "Mountain Dew",
"049000429183" : "Diet Coke",
"049000608779" : "Coca Cola",
"0018200969089" : "Shock Top"
]
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}