Coder Social home page Coder Social logo

pagedarray's Introduction

PagedArray

Version License Platform

PagedArray is a generic Swift data structure for helping you implement paging mechanisms in (but not limited to) UITableViews, UICollectionViews and UIPageViewControllers.

It is a Swift-version of its Objective-C equivalent AWPagedArray, which was used for implementing the techniques described in the blog post Fluent Pagination โ€“ no more jumpy scrolling.

PagedArray represents a list of optional elements stored by pages. It implements all the familiar Swift collection protocols so your datasource can use it just like a regular Array while providing an easy-to-use API for setting pages of data as they are retrieved.

// Initialize
var pagedArray = PagedArray<String>(count: 200, pageSize: 20)

// Set data pages
pagedArray.setElements(["A" ... "T"], pageIndex: 1)

// Retrieve data like a normal array containing optional elements
pagedArray.count // 200
pagedArray[0] // "A"
pagedArray[100] // nil

// Iterate
for element: String? in pagedArray {
    // Do magic
}

// Map, filter reduce
pagedArray.filter{ $0 != nil }.map{ $0! }.reduce("", combine:+) // "ABCDE..."

// Convert to array
Array(pagedArray) // ["A", "B", ... nil, nil]

UITableView example

Requirements

PagedArray is currently built for Swift 2.2 using Xcode 7.3

Installation

Embedded frameworks require a minimum deployment target of iOS 8 or OS X Mavericks.

To use PagedArray with a project targeting iOS 7, you must include the PagedArray.swift source file directly in your project.

Cocoapods

To integrate PagedArray into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

pod 'PagedArray', '~> 0.2'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate PagedArray into your Xcode project using Carthage, specify it in your Cartfile:

github "MrAlek/PagedArray" >= 0.3

Demo

The included example project shows a demo with a tweakable UITableViewController displaying a large number of rows using paging data.

Tests

The data structure is thoroughly tested by included XCUnit tests but no guarantees are given.

License

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

pagedarray's People

Contributors

mralek avatar miguelcampiao avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.