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 String { | |
| subscript(i: Int) -> Character? { | |
| guard i < self.count else { | |
| return nil | |
| } | |
| return self[self.index(self.startIndex, offsetBy: i)] | |
| } | |
| } |
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 Array where Element: Hashable { | |
| func counter() -> [Element: Int] { | |
| return self.reduce(into: [:]) { counts, elem in counts[elem, default: 0] += 1 } | |
| } | |
| } | |
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
| 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 |
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
| // 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 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
| 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 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 | |
| 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 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 | |
| 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 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 | |
| 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 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 | |
| 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 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
| #!/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 |