Skip to content

Instantly share code, notes, and snippets.

@newmarcel
Last active February 12, 2017 16:56
Show Gist options
  • Save newmarcel/e7206848efd84aa7f2b7 to your computer and use it in GitHub Desktop.
Save newmarcel/e7206848efd84aa7f2b7 to your computer and use it in GitHub Desktop.
UITableView+CATransaction
//
// UITableView+CATransaction.swift
//
// Created by Marcel Dierkes on 08.05.15.
// Copyright (c) 2015 Marcel Dierkes. All rights reserved.
//
import UIKit
import QuartzCore
public extension UITableView {
/**
Animates multiple insert, delete, reload, and move operations as a group.
Source: http://stackoverflow.com/a/12516056
- parameter updates: The block that performs the relevant insert, delete, reload, or move operations.
- parameter completion: A completion handler block to execute when all of the operations are finished. This block takes a single Boolean parameter that contains the value `YES` if all of the related animations completed successfully or `NO` if they were interrupted. This parameter may be `nil`.
*/
func performBatchUpdates(updates: (() -> Void)?, completion: ((finished: Bool) -> Void)?) {
CATransaction.begin()
CATransaction.setCompletionBlock {
completion?(finished: true)
}
self.beginUpdates()
updates?()
self.endUpdates()
CATransaction.commit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment