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
extension TitledCollectionView: UICollectionViewDelegate { | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
updateControllerDelegate(with: indexPath.item) | |
} | |
private func updateControllerDelegate(with item: Int) { | |
switch self.produce { | |
case .fruit: | |
let fruit = Fruit.allCases[item] | |
delegate?.itemWasSelected(fruit) |
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
extension TitledCollectionViewController: TitledCollectionViewDelegate { | |
func itemWasSelected(_ fruit: Fruit) { | |
print("Fruit named \(fruit.description) was selected") | |
} | |
func itemWasSelected(_ vegetable: Vegetable) { | |
print("Vegetable named \(vegetable.description) was selected") | |
} | |
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
extension TitledCollectionViewController: UICollectionViewDelegate { | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
print("tapped cell at \(indexPath)") | |
} | |
} |
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
private lazy var collectionView: UICollectionView = { | |
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: Layout()) | |
collectionView.register(ProduceCollectionViewCell.self, forCellWithReuseIdentifier: ProduceCollectionViewCell.identifier) | |
collectionView.dataSource = self | |
collectionView.translatesAutoresizingMaskIntoConstraints = false | |
return collectionView | |
}() |
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
extension TitledCollectionView: UICollectionViewDelegate { | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
updateControllerDelegate(with: indexPath.item) | |
} | |
private func updateControllerDelegate(with item: Int) { | |
switch self.produce { | |
case .fruit: | |
let fruit = Fruit.allCases[item] | |
print(produce?.description, fruit.description) |
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
import AudioToolbox.AudioServices | |
class TapticEngine { | |
/// 'Peek' feedback (single weak boom) | |
static func peek() { | |
AudioServicesPlaySystemSound(1519) | |
} | |
/// 'Pop' feedback (single strong boom) | |
static func pop() { | |
AudioServicesPlaySystemSound(1520) |
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
import AudioToolbox.AudioServices | |
class TapticEngine { | |
/// 'Peek' feedback (single weak boom) | |
static func peek() { | |
AudioServicesPlaySystemSound(1519) | |
} | |
/// 'Pop' feedback (single strong boom) | |
static func pop() { | |
AudioServicesPlaySystemSound(1520) |
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
class AlertView: UIView { | |
@IBOutlet var closeButton: UIButton! | |
@IBAction func close(_ sender: UIButton) { | |
TapticEngine.pop() | |
flash(closeButton) { [weak self] _ in | |
self?.removeFromSuperview() | |
} | |
} | |
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
import AudioToolbox.AudioServices | |
enum TapticEngine: UInt32 { | |
/// 'Peek' feedback (single weak boom) | |
case peek = 1519 | |
/// 'Pop' feedback (single strong boom) | |
case pop = 1520 | |
/// 'Cancelled' feedback (three sequential weak booms) | |
case cancelled = 1521 | |
/// provide haptic feedback to the user |
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
import UIKit | |
class InstructionViewController: UIViewController { | |
var titleText: String | |
var instructions: String | |
var image: UIImage | |
var caption: String? | |
var buttonTitle: String | |