• Stars
    star
    556
  • Rank 80,098 (Top 2 %)
  • Language
    Swift
  • Created over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ’Ύ πŸ”œπŸ“± Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)

DataSources

πŸ’Ύ πŸ”œπŸ“± Type-safe data-driven List-UI Framework. (We can also use ASCollectionNode)

Partial updates(insert, delete, move) of UICollectionView/UITableView is important things for fancy UI.
But, It's hard that synchronous of data and UI.
DataSources will solve this problem.

CI Status Version License Platform Carthage compatible FOSSA Status

Thanks

Diff-algorithm

Features

  • Data driven update
    • Data did change, then will display.
  • Partial updates, no more calling reloadData
    • Smooth and Faster.
    • if the count of changes larger than 300, update with non-animation.
  • Simplified usage
  • We can use different type each section.
  • Type-safe
    • We can take clearly typed object by IndexPath.
  • Using Adapter-pattern for List-UI
    • For example, We can also use this for ASCollectionNode of Texture. (Demo app includes it)
  • Reorder by UI operation
  • This library is not supported moving between section.

Requirements

  • Swift 4
  • iOS 9+

Usage (Example)

Conform protocol Diffable

public protocol Diffable {
  associatedtype Identifier : Hashable
  var diffIdentifier: Identifier { get }
}
struct Model : Diffable {

  var diffIdentifier: String {
    return id
  }
  
  let id: String
}

🀠 Most Simplified Usage

  1. Define SectionDataController in ViewController
let collectionView: UICollectionView

let sectionDataController = SectionDataController<Model, CollectionViewAdapter>(
  adapter: CollectionViewAdapter(collectionView: self.collectionView),
  isEqual: { $0.id == $1.id } // If Model has Equatable, you can omit this closure.
)

var models: [Model] = [] {
  didSet {
    sectionDataController.update(items: items, updateMode: .partial(animated: true), completion: {
      // Completed update
    })
  }
}

let dataSource = CollectionViewDataSource(sectionDataController: sectionDataController)

dataSource.cellFactory = { _, collectionView, indexPath, model in
   let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
   cell.label.text = model.title
   return cell
 }

collectionView.dataSource = dataSource

😎 Semi Manual

Single-Section (UICollectionView)

  1. Define SectionDataController in ViewController
let collectionView: UICollectionView
var models: [Model]

let sectionDataController = SectionDataController<Model, CollectionViewAdapter>(
  adapter: CollectionViewAdapter(collectionView: self.collectionView),
  isEqual: { $0.id == $1.id } // If Model has Equatable, you can omit this closure.
)
  1. Bind Models to SectionDataController in ViewController
var models: [Model] = […] {
  didSet {
    sectionDataController.update(items: items, updateMode: .partial(animated: true), completion: {
      // Completed update
    })
  }
}
  1. Implement UICollectionViewDataSource in ViewController
func numberOfSections(in collectionView: UICollectionView) -> Int {
  return 1
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  return sectionDataController.numberOfItems()
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
  let m = sectionDataController.item(for: indexPath)
  cell.label.text = m.title
  return cell
}

Multiple-Section (UICollectionView)

  1. Define DataController in ViewController
let collectionView: UICollectionView
var models: [Model]

let dataController = DataController<CollectionViewAdapter>(adapter: CollectionViewAdapter(collectionView: self.collectionView))
  1. Define Section<T> in ViewController
let section0 = Section(ModelA.self, isEqual: { $0.id == $1.id })
let section1 = Section(ModelB.self, isEqual: { $0.id == $1.id })
  1. Add Section to DataController

Order of Section will be decided in the order of addition.

dataController.add(section: section0) // will be 0 of section
dataController.add(section: section1) // will be 1 of section
  1. Bind Models to DataController
var section0Models: [ModelA] = […] {
  didSet {
    dataController.update(
      in: section0,
      items: section0Models,
      updateMode: .partial(animated: true),
      completion: {
        
    })
  }
}

var section1Models: [ModelA] = […] {
  didSet {
    dataController.update(
      in: section1,
      items: section1Models,
      updateMode: .partial(animated: true),
      completion: {
        
    })
  }
}
  1. Implement UICollectionViewDataSource
func numberOfSections(in collectionView: UICollectionView) -> Int {
  return dataController.numberOfSections()
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  return dataController.numberOfItems(in: section)
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

  return dataController.item(
    at: indexPath,    
    handlers: [
    .init(section: section0) { (m: ModelA) in
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
      cell.label.text = m.title
      return cell
    },
    .init(section: section1) { (m: ModelB) in
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
      cell.label.text = m.title
      return cell
      },
    ])

  /* Other way
  switch indexPath.section {
  case section0:
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
    let m = _dataController.item(at: indexPath, in: section0)
    cell.label.text = m.title
    return cell
  case section1:
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
    let m = _dataController.item(at: indexPath, in: section1)
    cell.label.text = m.title
    return cell
  default:
    fatalError()
  }
   */
}

Reorder by UI operation

SectionDataController has a snapshot for List-UI. It helps that perform batch update List-UI in safety.

But, the snapshots include side-effects. For example, if we did reorder items of List-UI by UI operation. In this time, Items of List-UI is caused differences to the snapshot. It will be caused unnecessary diff.

Therefore when we reorder items, we should operation followings.

  1. Reorder items of UI
  2. Call SectionDataController.reserveMoved(...
  3. Reorder items of Array
  4. Call SectionDataController.update(items: [T]..

Demo Application

This repository include Demo-Application. You can touch DataSources.

  1. Clone repository.
$ git clone https://github.com/muukii/DataSources.git
$ cd DataSources
$ pod install
  1. Open xcworkspace
  2. Run DataSourcesDemo on iPhone Simulator.

Author

muukii, [email protected], https://muukii.me/

License

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

FOSSA Status

More Repositories

1

NextGrowingTextView

πŸ“ The next in the generations of 'growing textviews' optimized for iOS 8 and above.
Swift
1,623
star
2

Rideau

πŸŽͺ Rideau is a drawer UI similar to what Apple's apps use. (e.g Maps, Shortcuts) Supports multiple snap points
Swift
473
star
3

StackScrollView

πŸ“‹ iOS Form UI Builder in Swift (powered by UICollectionView)
Swift
402
star
4

JAYSON

🧱 A JSON decoding/encoding library that handles optimistically or strictly.
Swift
249
star
5

MondrianLayout

πŸ— A way to build AutoLayout rapidly than using InterfaceBuilder(XIB, Storyboard) in iOS.
Swift
145
star
6

PrecisionLevelSlider

PrecisionLevelSlider
Swift
129
star
7

CPKenburnsView

CPKenburnsView is ken burns effect
Objective-C
105
star
8

ZoomImageView

UI component library to expand the photo, such as Apple's Photos app
Swift
97
star
9

LightRoom

Easy Chaining ImageFilter with CoreImage πŸ“Έ
Swift
94
star
10

CPKenburnsSlideshowView

Inspired by Hey Day
Objective-C
69
star
11

Bulk

πŸ‘¨β€πŸ’» Bulk is a library for buffering the objects. Pipeline(Sink) receives the object and emits the object bulked.
Swift
61
star
12

FluidInterfaceKit

🌧 A framework that provides the advanced infrastructure for your iPhone apps
Swift
53
star
13

TypedTextAttributes

πŸ– The Library Creating Text Attributes with Type-Safety
Swift
49
star
14

ColorCube

Create CubeData for CIColorCube from LUT image.
Swift
30
star
15

OneStore

πŸ“•A single value proxy for NSUserDefaults, with clean API.
Swift
27
star
16

cocoapods-frost

πŸ“¦ A plugin for CocoaPods that creates XCFramework(for internal distribution) for speeding up build time.
Ruby
27
star
17

jackhammer-syntax

Dark and Bright Syntax Theme
CSS
21
star
18

FluidPresentation

🍞 [Beta] A view controller that can unwind like presentation and navigation.
Swift
20
star
19

iOS7-Blur

Fast UIView Screenshot and BlurEffect
Objective-C
20
star
20

TextAttributesUtil

Quickly create NSAttributedString with TextAttributes
Swift
15
star
21

Presenter

Screen transition with safe and clean code.
Swift
14
star
22

Warehouse

Easy NSFileManager
Swift
13
star
23

MatchedTransition

[Used in Pairs] A primitive stuff to do transition
Swift
11
star
24

Bureau

An easy way to use input view to display custom-view on iOS UIKit
Swift
11
star
25

Drip.app

A photo editor app
Swift
11
star
26

chglog

πŸͺ΅ A changelog generator that regarding pulls and specified commits.
TypeScript
10
star
27

BoxLayout

[WIP] SwiftUI's interface like AutoLayout DSL
Swift
10
star
28

Sample.UmbrellaFramework

Swift
10
star
29

ModernUpperNotificationView

ModernUpperNotificationView is simple notification view - powered by
Swift
10
star
30

Capturer

πŸ“Έ A wrapper for AVCaptureSession - The way easier to use the Camera.
Swift
9
star
31

swiftui-GestureVelocity

In SwiftUI, a property-wrapper provides velocity in pt/s from gesture
Swift
9
star
32

MusicalScaleKit

Generate notes on Musical Scale
Swift
9
star
33

Grain

A data serialization template language in Swift
Swift
8
star
34

AutoresizingTableCollectionView

SampleCode Autoresizing Cells
Swift
7
star
35

ResultBuilderKit

Set of result builder
Swift
6
star
36

TextureBook

The sample codes using Texture.
Swift
6
star
37

CircleWaveAnimation-Playground

Swift
6
star
38

swiftui-WrapLayout

A custom layout built on top of SwiftUI's Layout API that lays elements out in multiple lines. Similar to flex-wrap in CSS, CollectionViewFlowLayout.
Swift
6
star
39

swiftui-AsyncMultiplexImage

Swift
5
star
40

RxFuture

πŸ›ΈA library to provide Future/Promise pattern API that is backed by RxSwift.
Swift
5
star
41

ViewFinder

Find the UI Component by accessibilityIdentifier from AppDelegate.window
Swift
5
star
42

CompositionKit

A collection of components to build composed component
Swift
5
star
43

Bound

β›“The Bound is a library for building iOS view transitions using UIViewPropertyAnimator.
Swift
5
star
44

ConcurrencyContinuationReproduce

[FB11707587] **`withCheckedContinuation`'s body will run on background thread in case of starting from main-actor.**.
Swift
5
star
45

Lab.swift

Just my playground space for learning Swift
Swift
5
star
46

TransitionPatch

Declarative sequence for converting value.
Swift
4
star
47

Unwrap

let _self = try self.unwrapped()
Swift
4
star
48

ViewSizeCalculator

Calculate UIView size
Swift
4
star
49

YogaBasedLayout

[WIP] Mondrian provides the layout interface like TetureGroup/Texture with high-optimized layout engine facebook/yoga flexbox implementation.
Swift
4
star
50

L10n.swift

Generate Localizable.strings from yaml (Work in progress)
Swift
4
star
51

Realm-EasyBackground

C++
4
star
52

Try.Umbrella

Swift
4
star
53

Play.ThrowBox

Trial about UISpringTimingParameters with UIViewPropertyAnimator
Swift
3
star
54

ColorGen

Generate .clr file from json
Objective-C
3
star
55

Swift-binary-size

Swift
3
star
56

RxAssert

Check element in Stream
Swift
3
star
57

APNsClient

[WIP] A desktop application to send a apns push with HTTP/2 based API. (Using VergeStore, Redux Arch)
Swift
3
star
58

BalloonUI

Swift
3
star
59

UpperNotificationController

UpperNotificationController is core for appear notification to upper on app screen
Swift
3
star
60

iOS15-UIRefreshControl-issue-reproduction

Swift
2
star
61

PhotosPicker

Swift
2
star
62

Simctl

Desktop Application Control Xcode's Simulator
JavaScript
2
star
63

dotfiles

Python
2
star
64

UpperNotificationView

UpperNotificaitonView
Objective-C
2
star
65

actions-xcode-install-simulator

Installs simulator runtime for Xcode development
2
star
66

swagger-ejs

HTML
2
star
67

RealmSwiftSupport

WIP
Swift
2
star
68

MuukiiPhoto

Swift
2
star
69

cocoapods-xcframework

[Not working] Integrates pods in form of prebuilt xcframeworks conveniently, reducing compile time
Ruby
2
star
70

RequestKit

Swift
2
star
71

playground

Welcome to my yard.
Swift
2
star
72

PhotosProvider

Swift
2
star
73

Play.RunLoopWaiter

Swift
2
star
74

issue-texture-swiftui-preview

reproduction for texture on swiftui preview
Swift
1
star
75

Garage

Swift
1
star
76

GitCommand.swift

Git-Command builder for Swift
Swift
1
star
77

ModuleKit

Tool for resource loading on Swift iOS Module (NSBundle(forClass: self.dynamicType)
Swift
1
star
78

ios-project-template

Swift
1
star
79

Reveal2Loader

Objective-C
1
star
80

atom-fruits

CSS
1
star
81

MBlurPopImageVIew

Objective-C
1
star
82

InputFieldView

Swift
1
star
83

EmbeddedStringsKit

Swift
1
star
84

Descriptors

Swift
1
star
85

RunLoopWaiter

Swift
1
star
86

ApplicationMonitor

Monitor life-cycle : Application-UIKit.
Swift
1
star
87

GeometryKit

Calculating geometry in CoreGraphics
Swift
1
star
88

electron-pusher

The Desktop Application Sending Apple Push Notification
JavaScript
1
star
89

framework-swift-interfaces

1
star
90

actions-xcode-create-simulator

Creates an iOS Simulator specified version and device
1
star
91

PlayTexture

The catalog of UI that laid out with Texture
Swift
1
star
92

RxSwiftPractice

Swift
1
star
93

PortalView

Swift
1
star
94

Quartz-Composer

1
star
95

Lightroom-Presets

1
star
96

Atom-Neka-Syntax

CSS
1
star
97

FigJam-Schema

TypeScript
1
star
98

figma-JSONSchema

TypeScript
1
star
99

IgnoreNilAssignmentOperator

value =? nil // This does not insert
Swift
1
star
100

RxUnsplashSource

https://source.unsplash.com/
Swift
1
star