Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
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!
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"
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)
}
extension Date {
func get(_ unit: Calendar.Component) -> Int {
return Calendar.current.component(unit, from: self)
}
var hour: Int {
return get(.hour)
}
<key>NSUserActivityTypes</key>
<dict>
<key>Refresh</key>
<string>com.vialyx.MVD.refresh_list</string>
</dict>
enum Shortcuts: String {
case refreshList = "com.vialyx.MVD.refresh_list"
var identifier: String {
return rawValue
}
var title: String {
switch self {
case .refreshList:
import IntentsUI
// MARK: - Life cycle
override func viewDidLoad() {
super.viewDidLoad()
// Call setup once at view did load
addObservers()
setupIntents()
}
// 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)
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let shortcut = Shortcuts(rawValue: userActivity.activityType) {
NotificationCenter.default.post(name: shortcut.notification, object: userActivity)
}
return true
}
struct YourStructure {
// Definition
}
class YourClass {
// Definition
}