| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "idiom" : "universal", | ||
| "filename" : "shirt01.jpg", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "version" : 1, | ||
| "author" : "xcode" | ||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "idiom" : "universal", | ||
| "filename" : "shirt02.jpg", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "version" : 1, | ||
| "author" : "xcode" | ||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "idiom" : "universal", | ||
| "filename" : "shirt03.jpg", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "version" : 1, | ||
| "author" : "xcode" | ||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "idiom" : "universal", | ||
| "filename" : "shirt04.jpg", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "version" : 1, | ||
| "author" : "xcode" | ||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "idiom" : "universal", | ||
| "filename" : "shirt05.jpg", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "version" : 1, | ||
| "author" : "xcode" | ||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "idiom" : "universal", | ||
| "filename" : "shirts.png", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "version" : 1, | ||
| "author" : "xcode" | ||
| } | ||
| } |
| @@ -0,0 +1,50 @@ | ||
| // | ||
| // ViewController.swift | ||
| // Coder-Swag | ||
| // | ||
| // Created by VICTOR CHU on 2018-02-09. | ||
| // Copyright © 2018 Victor Chu. All rights reserved. | ||
| // | ||
| import UIKit | ||
|
|
||
| class CategoriesVC: UIViewController, UITableViewDataSource, UITableViewDelegate{ | ||
|
|
||
| @IBOutlet weak var categoryTable: UITableView! | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| categoryTable.dataSource = self | ||
| categoryTable.delegate = self | ||
| } | ||
|
|
||
| func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
| return DataService.instance.getCategories().count | ||
| } | ||
|
|
||
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
| if let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryCell") as? CategoryCell { | ||
| let category = DataService.instance.getCategories()[indexPath.row] | ||
| cell.updateViews(category: category) | ||
| return cell | ||
| } | ||
| return CategoryCell() | ||
| } | ||
|
|
||
| func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
| let category = DataService.instance.getCategories()[indexPath.row] | ||
| performSegue(withIdentifier: "ProductsVC", sender: category) | ||
| } | ||
|
|
||
| override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | ||
| if let productsVC = segue.destination as? ProductsVC { | ||
| let barBtn = UIBarButtonItem() | ||
| barBtn.title = "" | ||
| navigationItem.backBarButtonItem = barBtn | ||
| assert(sender as? Category != nil) | ||
| productsVC.initProducts(category: sender as! Category) | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
| @@ -0,0 +1,42 @@ | ||
| // | ||
| // ProductsVC.swift | ||
| // Coder-Swag | ||
| // | ||
| // Created by VICTOR CHU on 2018-02-12. | ||
| // Copyright © 2018 Victor Chu. All rights reserved. | ||
| // | ||
| import UIKit | ||
|
|
||
| class ProductsVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { | ||
|
|
||
| @IBOutlet weak var productsCollection: UICollectionView! | ||
|
|
||
| private(set) public var products = [Product]() | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
|
|
||
| productsCollection.dataSource = self | ||
| productsCollection.delegate = self | ||
| } | ||
|
|
||
| func initProducts(category: Category) { | ||
| products = DataService.instance.getProducts(forCategoryTitle: category.title) | ||
| navigationItem.title = category.title | ||
| } | ||
|
|
||
| func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
| return products.count | ||
| } | ||
|
|
||
| func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
| if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductCell", for: indexPath) as? ProductCell { | ||
| let product = products[indexPath.row] | ||
| cell.updateViews(product: product) | ||
| return cell | ||
| } | ||
| return ProductCell() | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // Category.swift | ||
| // Coder-Swag | ||
| // | ||
| // Created by VICTOR CHU on 2018-02-09. | ||
| // Copyright © 2018 Victor Chu. All rights reserved. | ||
| // | ||
| import Foundation | ||
|
|
||
| struct Category { | ||
| private(set) public var title: String | ||
| private(set) public var imageName: String | ||
|
|
||
| init(title: String, imageName: String) { | ||
| self.title = title | ||
| self.imageName = imageName | ||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| // | ||
| // Product.swift | ||
| // Coder-Swag | ||
| // | ||
| // Created by VICTOR CHU on 2018-02-12. | ||
| // Copyright © 2018 Victor Chu. All rights reserved. | ||
| // | ||
| import Foundation | ||
|
|
||
| struct Product { | ||
| private(set) public var title: String | ||
| private(set) public var price: String | ||
| private(set) public var imageName: String | ||
|
|
||
| init(title: String, price: String, imageName: String) { | ||
| self.title = title | ||
| self.price = price | ||
| self.imageName = imageName | ||
| } | ||
| } |
| @@ -0,0 +1,78 @@ | ||
| // | ||
| // DataService.swift | ||
| // Coder-Swag | ||
| // | ||
| // Created by VICTOR CHU on 2018-02-09. | ||
| // Copyright © 2018 Victor Chu. All rights reserved. | ||
| // | ||
| import Foundation | ||
|
|
||
| class DataService { | ||
| static let instance = DataService() | ||
|
|
||
| private let categories = [ | ||
| Category(title: "SHIRTS", imageName: "shirts.png"), | ||
| Category(title: "HOODIES", imageName: "hoodies.png"), | ||
| Category(title: "HATS", imageName: "hats.png"), | ||
| Category(title: "DIGITAL", imageName: "digital.png") | ||
| ] | ||
|
|
||
| private let hats = [ | ||
| Product(title: "Devslopes Logo Graphic Beanie", price: "$18", imageName: "hat01.png"), | ||
| Product(title: "Devslopes Logo Hat Black", price: "$22", imageName: "hat02.png"), | ||
| Product(title: "Devslopes Logo Hat White", price: "$22", imageName: "hat03.png"), | ||
| Product(title: "Devslopes Logo Snapback", price: "$20", imageName: "hat04.png"), | ||
| ] | ||
|
|
||
| private let hoodies = [ | ||
| Product(title: "Devslopes Logo Hoodie Grey", price: "$32", imageName: "hoodie01.png"), | ||
| Product(title: "Devslopes Logo Hoodie Red", price: "$32", imageName: "hoodie02.png"), | ||
| Product(title: "Devslopes Logo Hoodie Grey", price: "$32", imageName: "hoodie03.png"), | ||
| Product(title: "Devslopes Logo Hoodie Black", price: "$32", imageName: "hoodie04.png"), | ||
| ] | ||
|
|
||
| private let shirts = [ | ||
| Product(title: "Devslopes Logo Shirt Black", price: "$18", imageName: "shirt01.png"), | ||
| Product(title: "Devslopes Badge Shirt Light Grey", price: "$18", imageName: "shirt02.png"), | ||
| Product(title: "Devslopes Logo Shirt Red", price: "$18", imageName: "shirt03.png"), | ||
| Product(title: "Hustle Delegate Grey", price: "$18", imageName: "shirt04.png"), | ||
| Product(title: "Kickflip Studios Black", price: "$18", imageName: "shirt05.png"), | ||
| ] | ||
|
|
||
| private let digitalGoods = [Product]() | ||
|
|
||
| func getProducts(forCategoryTitle title: String) -> [Product] { | ||
| switch title { | ||
| case "SHIRTS": | ||
| return getShirts() | ||
| case "HATS": | ||
| return getHats() | ||
| case "HOODIES": | ||
| return getHoodies() | ||
| case "DIGITAL": | ||
| return getDigitalGoods() | ||
| default: | ||
| return getShirts() | ||
| } | ||
| } | ||
|
|
||
| func getCategories() -> [Category] { | ||
| return categories | ||
| } | ||
|
|
||
| func getShirts() -> [Product] { | ||
| return shirts | ||
| } | ||
|
|
||
| func getHats() -> [Product] { | ||
| return hats | ||
| } | ||
|
|
||
| func getHoodies() -> [Product] { | ||
| return hoodies | ||
| } | ||
| func getDigitalGoods() -> [Product] { | ||
| return digitalGoods | ||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| // | ||
| // CategoryCell.swift | ||
| // Coder-Swag | ||
| // | ||
| // Created by VICTOR CHU on 2018-02-09. | ||
| // Copyright © 2018 Victor Chu. All rights reserved. | ||
| // | ||
| import UIKit | ||
|
|
||
| class CategoryCell: UITableViewCell { | ||
|
|
||
| @IBOutlet weak var categoryImage: UIImageView! | ||
| @IBOutlet weak var categoryTitle: UILabel! | ||
|
|
||
| func updateViews(category: Category) { | ||
| categoryImage.image = UIImage(named: category.imageName) | ||
| categoryTitle.text = category.title | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,22 @@ | ||
| // | ||
| // ProductCell.swift | ||
| // Coder-Swag | ||
| // | ||
| // Created by VICTOR CHU on 2018-02-12. | ||
| // Copyright © 2018 Victor Chu. All rights reserved. | ||
| // | ||
| import UIKit | ||
|
|
||
| class ProductCell: UICollectionViewCell { | ||
| @IBOutlet weak var productImage: UIImageView! | ||
| @IBOutlet weak var productTitle: UILabel! | ||
| @IBOutlet weak var productPrice: UILabel! | ||
|
|
||
| func updateViews(product: Product) { | ||
| productImage.image = UIImage(named: product.imageName) | ||
| productTitle.text = product.title | ||
| productPrice.text = product.price | ||
|
|
||
| } | ||
| } |