Skip to content

Commit

Permalink
Merge pull request #23 from zenangst/fix/crash-reloading-without-a-su…
Browse files Browse the repository at this point in the history
…perview

Add safe-guard for reloading without a superview
  • Loading branch information
zenangst authored Nov 5, 2019
2 parents ad682df + fa251ba commit da37a6a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Differific.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Differific"
s.summary = "A fast and convenient diffing framework"
s.version = "0.8.2"
s.version = "0.8.3"
s.homepage = "https://github.com/zenangst/Differific"
s.license = 'MIT'
s.author = { "Christoffer Winterkvist" => "[email protected]" }
Expand Down
7 changes: 7 additions & 0 deletions Source/iOS+tvOS/UICollectionView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ extension UICollectionView {
return
}

if superview == nil {
updateDataSource()
reloadData()
completion?()
return
}

setNeedsLayout()
layoutIfNeeded()

Expand Down
7 changes: 7 additions & 0 deletions Source/iOS+tvOS/UITableView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public extension UITableView {
return
}

if superview == nil {
updateDataSource()
reloadData()
completion?()
return
}

setNeedsLayout()
layoutIfNeeded()

Expand Down
7 changes: 7 additions & 0 deletions Source/macOS/NSCollectionView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public extension NSCollectionView {
return
}

if superview == nil {
updateDataSource()
reloadData()
completion?()
return
}

let manager = IndexPathManager()
let result = manager.process(changes, section: section)
let object = animations ? animator() : self
Expand Down
7 changes: 7 additions & 0 deletions Source/macOS/NSTableView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public extension NSTableView {
completion?()
return
}

if superview == nil {
updateDataSource()
reloadData()
completion?()
return
}

let manager = IndexPathManager()
let result = manager.process(changes, section: section)
Expand Down
4 changes: 4 additions & 0 deletions Tests/macOS/NSCollectionViewExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class NSCollectionViewExtensionsTests: XCTestCase {
let dataSource = DataSourceMock(models: ["Foo", "Bar", "Baz"])
let layout = NSCollectionViewFlowLayout()
layout.itemSize = CGSize(width: 250, height: 250)
let superview = NSView()
let collectionView = NSCollectionView(frame: .init(origin: .zero, size: layout.itemSize))
superview.addSubview(collectionView)
collectionView.collectionViewLayout = layout
collectionView.dataSource = dataSource
collectionView.register(NSCollectionViewItem.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier.init("cell"))
Expand Down Expand Up @@ -78,7 +80,9 @@ class NSCollectionViewExtensionsTests: XCTestCase {
let dataSource = DataSourceMock(models: ["Foo", "Bar", "Baz"])
let layout = NSCollectionViewFlowLayout()
layout.itemSize = CGSize(width: 250, height: 250)
let superview = NSView()
let collectionView = NSCollectionView(frame: .init(origin: .zero, size: layout.itemSize))
superview.addSubview(collectionView)
collectionView.collectionViewLayout = layout
collectionView.dataSource = dataSource
collectionView.register(NSCollectionViewItem.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier.init("cell"))
Expand Down

0 comments on commit da37a6a

Please sign in to comment.