Skip to content

Instantly share code, notes, and snippets.

View trilliwon's full-sized avatar
🎯
Focusing

WonJo trilliwon

🎯
Focusing
View GitHub Profile
@trilliwon
trilliwon / Bundle+.swift
Created August 8, 2020 11:49
decode json file
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.")
}
import UIKit
class FireworkView: UIView {
private let emitterLayer = CAEmitterLayer()
private let emitterCell = CAEmitterCell()
private let trailCell = CAEmitterCell()
private let fireworkCell = CAEmitterCell()
// MARK: - Initializers
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)?)
}
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 })
import UIKit
final class TagsView: UIView {
var didSelectTagItem: ((TagItem) -> Void) = { _ in }
typealias TagItem = String
typealias TagItemView = UIButton
var tags: [TagItem] = [] {
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
//: [Table of Contents](Table%20of%20Contents) | [Next](@next)
import Foundation
/*:
## Number Formatter
Provides localized representations of units and measurements.
*/
let numberFormatter = NumberFormatter()
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))
}
@trilliwon
trilliwon / UIColorExtensions.swift
Created July 29, 2020 10:26
Construct UIColor instance from hex value
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)
}
}
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()