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 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 { | |
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
// 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) |
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
#!/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 |
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 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 |
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 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 |
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 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 |
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 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 |
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
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) |
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
// 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() |
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
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 |