Skip to content

Instantly share code, notes, and snippets.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let contentView = ContentView()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
if let shortcutItem = connectionOptions.shortcutItem {
struct ContentView: View {
var body: some View {
Text("Hello, World!")
.contextMenu {
Button(action: {
// copy the content to the paste board
}) {
Text("Copy")
Image(systemName: "doc.on.doc")
}
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let tableView = UITableView()
let tasks = [
Task(id: "S_1001", name: "Laundry", description: "Wash all the clothes.", tagColor: .blue),
Task(id: "S_1002", name: "Pick up kids", description: "Pick up the kids from the school.", tagColor: .red),
Task(id: "S_1003", name: "Walk the dog", description: "Walk the dog in the morning", tagColor: .green),
Task(id: "S_1004", name: "Yoga class", description: "The yoga class begins at 5 pm.", tagColor: .purple)
]
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let task = tasks[indexPath.row]
return UIContextMenuConfiguration(identifier: task.id as NSString, previewProvider: nil) { _ in
let shareAction = UIAction(
title: "Share",
image: UIImage(systemName: "square.and.arrow.up")) { _ in
// share the task
}
let copyAction = UIAction(
title: "Copy",
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let task = tasks[indexPath.row]
return UIContextMenuConfiguration(identifier: task.id as NSString, previewProvider: nil) { _ in
let blueAction = UIAction(title: "Blue") { _ in }
let redAction = UIAction(title: "Red") { _ in }
let greenAction = UIAction(title: "Green") { _ in }
let purpleAction = UIAction(title: "Purple") { _ in }
let tagActions = UIMenu(title: "Change Tag Color...", children: [blueAction, redAction, greenAction, purpleAction])
let shareAction = UIAction(
title: "Share",
class TaskPreviewController: UIViewController {
let label = UILabel()
var task: Task!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
label.numberOfLines = 0
label.font = UIFont.systemFont(ofSize: 30)
view.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
guard let identifier = (configuration.identifier as? NSString) as String? else { return }
let task = tasks.first { $0.id == identifier }
if task != nil {
animator.addCompletion {
let previewController = TaskPreviewController()
previewController.task = task
self.show(previewController, sender: self)
}
}
from datetime import datetime
datetime(2020, 1, 10, 13, 2, 0)
# a datetime object by specifying year, month, day, hour, minute, second
datetime.today()
# a datetime object with current date and time
datetime.now()
# the same as above when tz is None
datetime.utcnow()
# the same as above, but in the UTC (Coordinated Universal Time)
class Attributes
date year, month, day
time hour, minute, second, microsecond, tzinfo
datetime year, month, day, hour, minute, second, microsecond, tzinfo
Element Type Element Number count == 0 isEmpty
Int 0 92.98 78.63
Int 1 76.66 79.90
Int 10 76.92 78.67
Int 100 76.04 77.78
Int 1000 74.46 78.05
Int 10000 78.50 79.11
Int 100000 75.58 78.18
Int 1000000 75.15 77.57
Int 10000000 76.12 79.11