Skip to content

Instantly share code, notes, and snippets.

View froggomad's full-sized avatar

Kenny Dubroff (froggomad) froggomad

View GitHub Profile
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)
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")
}
extension TitledCollectionViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("tapped cell at \(indexPath)")
}
}
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
}()
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)
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)
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)
class AlertView: UIView {
@IBOutlet var closeButton: UIButton!
@IBAction func close(_ sender: UIButton) {
TapticEngine.pop()
flash(closeButton) { [weak self] _ in
self?.removeFromSuperview()
}
}
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
import UIKit
class InstructionViewController: UIViewController {
var titleText: String
var instructions: String
var image: UIImage
var caption: String?
var buttonTitle: String