Skip to content

Instantly share code, notes, and snippets.

View trilliwon's full-sized avatar
🎯
Focusing

WonJo trilliwon

🎯
Focusing
View GitHub Profile
import Foundation
import UIKit
// Usage Examples
let shadowColor = Color.shadow.value
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5)
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value
enum Color {
@trilliwon
trilliwon / uiimage-data.swift
Last active January 12, 2024 14:45
Swift UIImage to Data, Data to UIImage
// Swift4
let image = UIImage(named: "sample")
let data = image?.pngData()
let data = image?.jpegData(compressionQuality: 0.9)
let uiImage: UIImage = UIImage(data: imageData)
// deprecated
// var imageData: Data = UIImagePNGRepresentation(image)
@trilliwon
trilliwon / makeI18N.sh
Last active January 11, 2022 08:03
makeI18N
#!/bin/sh
echo "generating I18N.swift"
touch tempI18N.swift
echo "struct I18N {" >> tempI18N.swift
inputfile=${SRCROOT}/Pomodoro/Resources/en.lproj/Localizable.strings
while IFS= read -r line
import UIKit
class ToLeftSegue: UIStoryboardSegue {
override func perform() {
let sourceView = self.source.view as UIView!
let destinationView = self.destination.view as UIView!
let screenWidth = UIScreen.main.bounds.size.width
import UIKit
class ToLeftSegueUnwind: UIStoryboardSegue {
override func perform() {
let sourceView = self.source.view as UIView!
let destinationView = self.destination.view as UIView!
let screenWidth = UIScreen.main.bounds.size.width
import UIKit
class FadeInOut: UIStoryboardSegue {
override func perform() {
let sourceView: UIView = self.source.view as UIView!
let destinationView: UIView = self.destination.view as UIView!
sourceView.alpha = 1.0
import UIKit
class FadeInOutUnwind: UIStoryboardSegue {
override func perform() {
let sourceView: UIView = self.source.view as UIView!
let destinationView: UIView = self.destination.view as UIView!
sourceView.alpha = 1.0
@trilliwon
trilliwon / uitableview-swipe-actions.swift
Last active September 13, 2021 14:14
uitableview-swipe-actions
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let share = UIContextualAction(style: .normal, title: "Share") { action, view, completion in
completion(true)
}
let delete = UIContextualAction(style: .destructive, title: "Delete") { [weak self] action, view, completion in
self?.langs.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
@trilliwon
trilliwon / haptic.swift
Created August 29, 2018 05:42
iOS haptic feedback code
// class UINotificationFeedbackGenerator
let notificationFeedback = UINotificationFeedbackGenerator()
notificationFeedback.notificationOccurred(.success) // .warning, .error
// class UIImpactFeedbackGenerator
let impactFeedback = UIImpactFeedbackGenerator(style: .light) // .medium, .heavy
impactFeedback.impactOccurred()
// class UISelectionFeedbackGenerator
let selectionFeedback = UISelectionFeedbackGenerator()
@trilliwon
trilliwon / latency.txt
Created September 6, 2018 09:09 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD