This file contains 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 Bundle { | |
func decode<T: Decodable>(_ type: T.Type, from file: String) -> T { | |
guard let url = url(forResource: file, withExtension: nil) else { | |
fatalError("Failed to locate \(file) in bundle.") | |
} | |
guard let data = try? Data(contentsOf: url) else { | |
fatalError("Failed to load \(file) from bundle.") | |
} |
This file contains 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 FireworkView: UIView { | |
private let emitterLayer = CAEmitterLayer() | |
private let emitterCell = CAEmitterCell() | |
private let trailCell = CAEmitterCell() | |
private let fireworkCell = CAEmitterCell() | |
// MARK: - Initializers |
This file contains 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 AVFoundation | |
import Photos | |
import UIKit | |
import UserNotifications | |
protocol PermissionCheckable { | |
func doAfterNotificationPermission(workItem: ((Bool) -> Void)?) | |
func doAfterVideoPermission(workItem: ((Bool) -> Void)?) | |
func doAfterPhotoPermission(workItem: ((Bool) -> Void)?) | |
} |
This file contains 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 RaindropView: UIView { | |
var images: [CGImage] { | |
return [UIImage(named: "rain"), | |
UIImage(named: "rain"), | |
UIImage(named: "rain"), | |
UIImage(named: "rain"), | |
UIImage(named: "rain")].map({ $0?.cgImage }).compactMap({ $0 }) |
This file contains 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 | |
private let kOscillationAnimationKey = "oscillation" | |
class MusicEqualizerView: UIView { | |
var barCount: Int = 4 | |
var barInterval: CGFloat = 0.2 | |
var barIdleHeight: CGFloat = 0.2 | |
var barMinPeakHeight: CGFloat = 0.3 |
This file contains 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
//: [Table of Contents](Table%20of%20Contents) | [Next](@next) | |
import Foundation | |
/*: | |
## Number Formatter | |
Provides localized representations of units and measurements. | |
*/ | |
let numberFormatter = NumberFormatter() |
This file contains 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 CoreGraphics | |
extension CGPoint { | |
/// Calculates the distance between two points in 2D space. | |
/// + returns: The distance from this point to the given point. | |
func distance(to point: CGPoint) -> CGFloat { | |
return sqrt(pow(point.x - self.x, 2) + pow(point.y - self.y, 2)) | |
} | |
This file contains 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 UIColor { | |
/// UIColor(hex: 0x000000) | |
convenience init(hex: Int, alpha: CGFloat = 1) { | |
let r = CGFloat((hex & 0xFF0000) >> 16) / 255 | |
let g = CGFloat((hex & 0xFF00) >> 8) / 255 | |
let b = CGFloat((hex & 0xFF)) / 255 | |
self.init(red: r, green: g, blue: b, alpha: alpha) | |
} | |
} |
This file contains 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 | |
final class ScrollingPageControl: UIView { | |
// The number of dots | |
var pages: Int = 0 { | |
didSet { | |
guard pages != oldValue else { return } | |
pages = max(0, pages) | |
invalidateIntrinsicContentSize() |