Beginning Collection Views - Part 19: Section 2: | Ray Wenderlich

In this short video you'll learn about a property which will to enable you to longpress on a collection view and move cells around.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4448-beginning-collection-views/lessons/19

Hi, Catie & Jessy!
Thank you for great course! (and for authors of original courses) )
A little question about DataSource.swift:

private func loadParksFromDisk() -> [Park] {
	sections.removeAll(keepingCapacity: false)

Why do you use .removeAll instead of assiging an empty array? Does this approach has any (theoretical) performance or stylistic advantages or just a matter of personal preferences?

Thank you in advance!

Syntactically, removeAll makes better sense to me personally since you are clearing up an existing array and adding new elements to it. But functionally (and performance-wise) I believe both removeAll and assigning an empty array do about the same thing.

See the following Stack Overflow thread if you are interested in the nitty gritty details:

1 Like

Hi catie & Jessy,
We can move single cell at a time which is really cool. Is it possible to move multiple cells at a time? Any possible approach.

You should be able to move multiple cells at a time around using the new Drag & Drop API in iOS 11. Take a look at the following WWDC video to see the details:

Hi Catie & Jessy,
A little extra feature I am curious about:
How would you approach to move cells only within the sections?

@catie Can you please help with this when you get a chance? Thank you - much appreciated! :]