Skip to content

Instantly share code, notes, and snippets.

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool
{
return true
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)
{
let item = self.items[sourceIndexPath.row]
self.items.remove(at: sourceIndexPath.row)
self.items.insert(item, at: destinationIndexPath.row)
func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator)
{
let destinationIndexPath: IndexPath
if let indexPath = coordinator.destinationIndexPath
{
destinationIndexPath = indexPath
}
else
{
// Get last index path of collection view.
let items = coordinator.items
if items.count == 1, let item = items.first, let sourceIndexPath = item.sourceIndexPath
{
var dIndexPath = destinationIndexPath
if dIndexPath.row >= collectionView.numberOfItems(inSection: 0)
{
dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1
}
collectionView.performBatchUpdates({
self.items.remove(at: sourceIndexPath.row)
func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters?
{
let previewParameters = UIDragPreviewParameters()
previewParameters.visiblePath = UIBezierPath(rect: CGRect(x: 25, y: 25, width: 120, height: 120))
return previewParameters
}
collectionView.performBatchUpdates({
var indexPaths = [IndexPath]()
for (index, item) in coordinator.items.enumerated()
{
//Destination index path for each item is calculated separately using the destinationIndexPath fetched from the coordinator
let indexPath = IndexPath(row: destinationIndexPath.row + index, section: destinationIndexPath.section)
self.items.insert(item.dragItem.localObject as! String, at: indexPath.row)
indexPaths.append(indexPath)
}
collectionView.insertItems(at: indexPaths)
{
"size":{
"width":150,
"height":150
},
"name":"Apple"
}
let items = coordinator.items
var dIndexPath = destinationIndexPath
if dIndexPath.row >= collectionView.numberOfItems(inSection: 0)
{
dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1
}
var sourceIndexPaths = [IndexPath]()
var destinationIndexPaths = [IndexPath]()
for item in items
{
let gradientLayer = CAGradientLayer()
gradientLayer.colors = [UIColor.purple.cgColor, UIColor.yellow.cgColor]
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 1, y: 1)
gradientLayer.frame = view.bounds
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
//granted = yes, if app is authorized for all of the requested interaction types
//granted = no, if one or more interaction type is disallowed
}
//Actions
let remindLaterAction = UNNotificationAction(identifier: "remindLater", title: "Remind me later", options: UNNotificationActionOptions(rawValue: 0))
let acceptAction = UNNotificationAction(identifier: "accept", title: "Accept", options: .foreground)
let declineAction = UNNotificationAction(identifier: "decline", title: "Decline", options: .destructive)
let commentAction = UNTextInputNotificationAction(identifier: "comment", title: "Comment", options: .authenticationRequired, textInputButtonTitle: "Send", textInputPlaceholder: "Share your thoughts..")
//Category
let invitationCategory = UNNotificationCategory(identifier: "INVITATION", actions: [remindLaterAction, acceptAction, declineAction, commentAction], intentIdentifiers: [], options: UNNotificationCategoryOptions(rawValue: 0))
//Register the app’s notification types and the custom actions that they support.