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
func ensureRange<T>(value: T, minimum: T, maximum: T) -> T where T : Comparable { | |
return min(max(value, minimum), maximum) | |
} |
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
func dataSourceForQuery(_ query: Query) -> CategorySessionsTableViewDataSource { | |
return CategorySessionsTableViewDataSource(query: query) { (changes, sessions) in | |
// Success: Perform batch remove / insert of cells | |
if #available(iOS 11.0, *) { | |
self.tableView.performBatchUpdates({ | |
self.performUpdates(for: changes) | |
}, completion: nil) | |
} |
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
// min(max()) example for scrolling | |
let minValue: CGFloat = 0 | |
let maxValue: CGFloat = 1 | |
let dynamicValue = (trackCell.trackImageView.frame.size.height - locationY) / trackCell.trackImageView.frame.size.height | |
let delta = min(maxValue, max(minValue, dynamicValue) |
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
/// Fades current player to specified `volume` with specified `duration`. | |
public func fadeTo(volume: Float, duration: TimeInterval = 5.0, completionHandler: @escaping () -> Void) { | |
// Current player | |
let player = self.currentPlayer | |
// Calculated increments for volume steps | |
let volumeIncrementationRate = 0.15 // Volume adjustments pr. seconds | |
let volumeDistance = player.volume - volume | |
let volumeSteps = duration / volumeIncrementationRate |
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
func dataSourceForQuery(_ query: Query) -> FeaturedSessionsCollectionViewDataSource { | |
return FeaturedSessionsCollectionViewDataSource(query: query) { (changes, _) in | |
// Perform batch remove / insert of cells | |
self.collectionView?.performBatchUpdates({ | |
for (index, change) in changes.enumerated() { | |
let indexPath = IndexPath(row: index, section: 0) | |
switch change.type { | |
case .added: | |
self.collectionView?.insertItems(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
import UIKit | |
import AVFoundation | |
class ViewController: UIViewController { | |
// Duplicate players to handle optional cross-fading. | |
let playerQueue = [AVPlayer(), AVPlayer()] | |
var timeObserverToken: Any? |
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
// | |
// ViewController.swift | |
// ColorScroll | |
// | |
// Created by Michael Nino Evensen on 25/09/2019. | |
// Copyright © 2019 Michael Nino Evensen. All rights reserved. | |
// | |
import UIKit |
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 UIImage { | |
var averageColor: UIColor? { | |
guard let inputImage = CIImage(image: self) else { return nil } | |
let extentVector = CIVector(x: inputImage.extent.origin.x, y: inputImage.extent.origin.y, z: inputImage.extent.size.width, w: inputImage.extent.size.height) | |
guard let filter = CIFilter(name: "CIAreaAverage", parameters: [kCIInputImageKey: inputImage, kCIInputExtentKey: extentVector]) else { return nil } | |
guard let outputImage = filter.outputImage else { return nil } | |
var bitmap = [UInt8](repeating: 0, count: 4) | |
let context = CIContext(options: [.workingColorSpace: kCFNull]) |
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
// | |
// LocalCollection.swift | |
// Slow | |
// | |
// Created by Michael Nino Evensen on 20/08/2019. | |
// Copyright © 2019 Michael Nino Evensen. All rights reserved. | |
// | |
import FirebaseFirestore |
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
// | |
// Copyright (c) 2018 Google Inc. | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software |