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
// MARK: - INUIAddVoiceShortcutViewControllerDelegate | |
extension TransportListViewController: INUIAddVoiceShortcutViewControllerDelegate { | |
@available(iOS 12.0, *) | |
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) { | |
print("addVoiceShortcutViewController didFinishWith voiceShortcut: \(String(describing: voiceShortcut)) error: \(String(describing: error))") | |
setupIntents() | |
controller.dismiss(animated: true, completion: nil) | |
} | |
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 IntentsUI | |
// MARK: - Life cycle | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Call setup once at view did load | |
addObservers() | |
setupIntents() | |
} |
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
enum Shortcuts: String { | |
case refreshList = "com.vialyx.MVD.refresh_list" | |
var identifier: String { | |
return rawValue | |
} | |
var title: String { | |
switch self { | |
case .refreshList: |
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
<key>NSUserActivityTypes</key> | |
<dict> | |
<key>Refresh</key> | |
<string>com.vialyx.MVD.refresh_list</string> | |
</dict> |
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 Date { | |
func get(_ unit: Calendar.Component) -> Int { | |
return Calendar.current.component(unit, from: self) | |
} | |
var hour: Int { | |
return get(.hour) | |
} | |
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 Date { | |
func add(_ unit: Calendar.Component, value: Int) -> Date { | |
return Calendar.current.date(byAdding: unit, value: value, to: self)! | |
} | |
func add(year: Int) -> Date { | |
return add(.year, value: year) | |
} | |
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 Date { | |
var time: Date? { | |
let components = Calendar.current.dateComponents([.hour, .minute], from: self) | |
return Calendar.current.date(from: components) | |
} | |
} | |
let today = Date() // "Sep 17, 2018 at 7:49 PM" |
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
let startOfDay = Calendar.current.startOfDay(for: Date()) | |
let dateInterval = DateInterval(start: startOfDay, duration: 8 * 60 * 60) | |
let meetingDate = startOfDay + 13 * 60 * 60 | |
print("Are we have a meeting today?: \(dateInterval.contains(meetingDate))") | |
// Are we have a meeting today?: false | |
// Yeah! Today a good day for productive work without meetings! |
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
let startOfDay = Calendar.current.startOfDay(for: Date()) | |
let endOfDay = startOfDay + 8 * 60 * 60 | |
let dateInterval = DateInterval(start: startOfDay, end: endOfDay) | |
let startLunch = startOfDay + 4 * 60 * 60 | |
let lunchInterval = DateInterval(start: startLunch, duration: 60 * 60) | |
print("intersection: \(String(describing: dateInterval.intersection(with: lunchInterval)))") | |
// intersection: Optional(2018-09-17 01:00:00 +0000 to 2018-09-17 02:00:00 +0000) | |
print("intersects: \(dateInterval.intersects(lunchInterval))") |
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 Date { | |
func compareTime(with date: Date) -> ComparisonResult { | |
var components = DateComponents() | |
components.hour = calendar.component(.hour, from: self) | |
components.minute = calendar.component(.minute, from: self) | |
var withComponents = DateComponents() | |
withComponents.hour = calendar.component(.hour, from: date) | |
withComponents.minute = calendar.component(.minute, from: date) |