Skip to content

Instantly share code, notes, and snippets.

View vulgur's full-sized avatar
🏠
Working from home

Wang Shudao vulgur

🏠
Working from home
View GitHub Profile
@vulgur
vulgur / README-Template.md
Created February 25, 2019 02:10 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@vulgur
vulgur / ProductTableViewController.swift
Created August 11, 2018 15:13
[Leading and Trailing Action on Cell] #swipe
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let product = dataStore?.products[indexPath.row] else {
return nil
}
let addAction = UIContextualAction(style: .normal, title: "Add") { [weak self](action, view, completionHandler) in
guard let `self` = self else {
completionHandler(false)
return
}
@vulgur
vulgur / ShoppingListViewController.swift
Created August 11, 2018 14:23
[UITableViewDropDelegate] #drop
extension ShoppingListViewController: UITableViewDropDelegate {
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
guard let destinationIndexPath = coordinator.destinationIndexPath else {
return
}
DispatchQueue.main.async { [weak self] in
tableView.beginUpdates()
coordinator.items.forEach({ (item) in
guard let sourceIndexPath = item.sourceIndexPath,
let `self` = self
@vulgur
vulgur / ShoppingListViewController.swift
Created August 11, 2018 10:07
[UITableViewDragDelegate] #drag
extension ShoppingListViewController: UITableViewDragDelegate {
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let listItem = shoppingList[indexPath.row]
let provider = NSItemProvider(object: listItem)
let dragItem = UIDragItem(itemProvider: provider)
return [dragItem]
}
}
@vulgur
vulgur / Singleton.swift
Created August 11, 2018 05:58
[Swift Singleton] #swift #singleton #designpattern
class Singleton {
static let instance = Singleton()
}