Skip to content

Instantly share code, notes, and snippets.

View mike-ferenduros's full-sized avatar

Mike Ferenduros mike-ferenduros

View GitHub Profile
@mike-ferenduros
mike-ferenduros / UICollectionView+batchUpdate.swift
Created September 25, 2018 12:53
Update UICollectionView based on before and after arrays
extension UICollectionView {
///Perform batch update based on before and after arrays
///An array must not contain duplicate values
func batchUpdate<T: Equatable>(section: Int, from oldData: [T], to newData: [T], completion: ((Bool) -> Void)? = nil) {
performBatchUpdates({
let deletions = oldData.indices.filter { !newData.contains(oldData[$0]) }
deleteItems(at: deletions.map { IndexPath(item: $0, section: section) })
let insertions = newData.indices.filter { !oldData.contains(newData[$0]) }
insertItems(at: insertions.map { IndexPath(item: $0, section: section) })
@mike-ferenduros
mike-ferenduros / Cardboard.swift
Last active April 27, 2022 12:08
Decode Cardboard calibration data retrieved from a Cardboard QR code.
//
// Cardboard.swift
//
// Created by Michael Ferenduros on 27/09/2016.
// Copyright © 2016 Mike Ferenduros. All rights reserved.
//
import Foundation
extension Int64 : _ObjectiveCBridgeable
{
public init(_ number: NSNumber)
{
self.init(number.longLongValue)
}
public func _bridgeToObjectiveC() -> NSNumber
{
return NSNumber(longLong: self)