Skip to content

Instantly share code, notes, and snippets.

let jsonString = """
{
"type":"fruit",
"size":{
"width":150,
"height":150
},
"title":"Apple",
"url":"https:\\/\\/www.fruits.com\\/apple",
"isSample":true,
struct Photo: Codable
{
//...Other properties (described in Code Snippet - 1)...
//This property is not included in the CodingKeys enum and hence will not be encoded/decoded.
var format: String = "png"
enum CodingKeys: String, CodingKey
{
case title = "name"
let jsonString = """
{
"type":"fruit",
"size":{
"width":150,
"height":150
},
"name":"Apple",
"link":"https:\\/\\/www.fruits.com\\/apple",
"isSample":true,
struct Photo: Codable
{
var title: String
var size: Size
enum CodingKeys: String, CodingKey
{
case title = "name"
case size
}
{
"title":"Apple",
"width":150,
"height":150
}
struct Photo
{
var title: String
var size: Size
enum CodingKeys: String, CodingKey
{
case title = "name"
case width
case height
class City: NSObject, NSCoding
{
var name: String?
var id: Int?
required init?(coder aDecoder: NSCoder)
{
self.name = aDecoder.decodeObject(forKey: "name") as? String
self.id = aDecoder.decodeObject(forKey: "id") as? Int
}
func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem]
{
let item = self.items[indexPath.row]
let itemProvider = NSItemProvider(object: item as NSString)
let dragItem = UIDragItem(itemProvider: itemProvider)
dragItem.localObject = item
return [dragItem]
}
func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal
{
if session.localDragSession != nil
{
if collectionView.hasActiveDrag
{
return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
else
{
func collectionView(_ collectionView: UICollectionView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem]
{
let item = self.items[indexPath.row]
let itemProvider = NSItemProvider(object: item as NSString)
let dragItem = UIDragItem(itemProvider: itemProvider)
dragItem.localObject = item
return [dragItem]
}