Skip to content

Instantly share code, notes, and snippets.

View icanswiftabit's full-sized avatar
⌨️

Błażej Wdowikowski icanswiftabit

⌨️
View GitHub Profile
coordinator.session.loadObjects(ofClass: Cat.self) { cats in
collectionView.performBatchUpdates {
for cat in cats as! [Cat] {
self.viewModel.cats.insert(cat, at: destinationIndexPath.row)
}
collectionView.reloadSections(IndexSet(integer: destinationIndexPath.section))
}
}
func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal {
let operation: UIDropOperation = session.localDragSession == nil ? .copy : .move
let intent = UICollectionViewDropIntent.insertAtDestinationIndexPath
let dropProposal = UICollectionViewDropProposal(operation: operation, intent: intent)
return dropProposal
}
for item in session.items {
item.itemProvider.loadObject...
}
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
session.loadObjects(ofClass: NSString.self) { item in
DispatchQueue.main.async {
label.text = item as NSString as String
}
}
}
func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {
return UIDropProposal(operation: .copy)
}
func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool {
return session.hasItemsConforming(toTypeIdentifiers: [kUTTypePlainText as String])
}
func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] {
let provider = NSItemProvider(object: "Hello" as NSString)
return [UIDragItem(itemProvider: provider)]
}
collectionView.pasteConfiguration = UIPasteConfiguration(forAccepting: UIImage.self)
...
override func paste(itemProviders: [NSItemProvider]) {
for provider in itemProviders {
provider.loadObject(ofClass: UIImage.self, completionHandler: { item, error in
guard error == nil else {
return
}
// example your_app_dir/.bundle/config
— -
BUNDLE_PATH: “.gems”
BUNDLE_DISABLE_SHARED_GEMS: “true”
//example Gemfile
source ‘https://rubygems.org'
gem ‘cocoapods’
gem ‘cocoapods-keys’
gem ‘redcarpet’
gem ‘rswift-ios’