Latest 0.2.1
License MIT
Platforms ios 8.0
Dependencies Differ

CI Status


To run the example project, clone the repo, and run pod install from the Example directory first.



InsidedCollectionView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'InsidedCollectionView'


Just import the module, instantiate a manager with the range you want, and use the manager methods to get your proper indexes instead of the computed ones

import InsidedCollectionView

class ViewController: UIViewController {

    @IBOutlet weak var collectionView: UICollectionView!

    let insideCollectionViewManager = InsidedCollectionViewManager(range: 3)

extension ViewController: UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return insideCollectionViewManager.numberOfElementCountingInserted(inCount: itemsCount)

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "reuseIdentifier", for: indexPath)

        if insideCollectionViewManager.isInserted(indexPath: indexPath) {
            let adIndexPath = insideCollectionViewManager.insertedIndex(indexPath: indexPath)
            cell.configureAd(adNumber: adIndexPath.row)
        } else {
            let myIndexPath = insideCollectionViewManager.trueIndexPath(indexPath: indexPath)
            let item = items[myIndexPath.row]
        return cell

extension ViewController: UICollectionViewDelegate {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if insideCollectionViewManager.isInserted(indexPath: indexPath) {
            print("selected inserted item at", insideCollectionViewManager.insertedIndex(indexPath: indexPath).row)
        } else {
            let trueIndex = insideCollectionViewManager.trueIndexPath(indexPath)
            print("selected item at",  trueIndex.row)

You can change the range at runtime, but remember to call reloadData on your collectionView !

insideCollectionViewManager.range = 14

If you want to insert / delete / move items, use the corresponding methods of InsidedCollectionViewManager :

open func insertItems(at indexPaths: [IndexPath], beforeCount: Int, inCollectionView: UICollectionView)
open func deleteItems(at indexPaths: [IndexPath], beforeCount: Int, inCollectionView: UICollectionView)
open func reloadItems(at indexPaths: [IndexPath], inCollectionView: UICollectionView)
open func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, inCollectionView: UICollectionView)

For insertion and deletion, you must pass the number of items (your items, not counting inserted ones) that are here BEFORE your insertion / deletion. That way the manager can compute how many inserted cells are needed, insert and add them accoridngly, and add your new items at their proper new index. See the example if needed.


Philippe Auriach


InsidedCollectionView is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "InsidedCollectionView",
    "version": "0.2.1",
    "summary": "Allow inserting cells at specific interval in a collectionView or tableView without changing all indexes. Cool for inserting ads.",
    "description": "You want to add some ads in your collection view without changing your model behind your data source ? Just specify the interval, and use the method provided by the manager to get your count and indexes. All the new indexes computation is made for you! It also handles inserting / deleting methods, without changing the intervals inserted items are at.",
    "homepage": "",
    "screenshots": [
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "PhilippeAuriach": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.1"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0"
    "source_files": "InsidedCollectionView/Classes/**/*",
    "swift_version": "4.0",
    "dependencies": {
        "Differ": [
            "~> 1.3"

Pin It on Pinterest

Share This