Bring ComponentKit to Swift, A React-inspired view framework for iOS

License: MIT

Language: Objective-C++

Keywords: componentkit, ios, listview, react, swift, wrapper

Platform Swift Build Status

ComponentSwift brings ComponentKit to swift.

ComponentKit is a react-inspired native view framework for iOS developed by Facebook. It intruduces a new abstract layer (component) to automatically handle view reuse, meanwhile provide the ability to build smooth list view easily.

ComponentSwift is an objc wrapper of ComponentKit and refined for swift. ComponentSwift is designed to be a subset of ComponentKit, implementing the most commonly used features.


class CellComponent: CompositeComponent {

    init?(text: String) {
            getAnotherComponent(text) //
// ...

or try real demo with pod try ComponentSwift

Supported Features


  • Component:
    • almost all build-in components.
    • ability to wrap an an existed CKComponent on your own
  • Datasource:
    • CollectionViewTransactionalDatasource
    • TableViewTransactionalDatasource (unofficial)
    • HostingView
  • Response Chain and Actions
  • Scope and State
  • Animation

Not support:

  • component controller and StatefulViewComponent
  • things about viewContext, mount
  • computeLayoutThatFits: overriding
  • ...

Work with legacy code

Legacy CKComponent classes could continue to work in swift when using ComponentSwift. Classes and methods are provided to wrap your legacy components conveniently. Every attributes in ComponentKit have an equivalent in ComponentSwift.

Subclass CSCompositeComponent and use initWithCKComponent in its implementation. Import ComponentSubclass.h to use this stuff. Reference more from WrapExisted in the demo project.

more document here


ComponentKit is implemented and used with objc++, which is pretty cool. It's incompatible with swift, since swift doesn't support objc++. So comes the ComponentSwift.

A objc wrapper is implemented to bridge componentKit to swift. It create an objc version equivalent for every type in componentKit's APIs, objc class for c++ struct/class, hiding the c++ header in the implementation. It doesn't touch deep in componentKit. The runtime code is almost the same to the one using componentKit directly in the simplest situation except for construction of objc layer, so it's safe to use.

It refined the bridged interface for swift, including notating nullability, adding default parameter and swift-only api. C++'s aggregate initialization is very expressive in componentKit. ComponentSwift try hard to simulate the api with default parameters and ExpressibleByXXXLiteral. At least we got code completion here.


pod "ComponentSwift"

The lib is released with ComponentKit v0.15.1, whose latest version drop support of cocoapods. For version 0.20, go to branch 0.20.


ComponentSwift is available under the MIT license.

Project Statistics

Sourcerank 6
Repository Size 320 KB
Stars 33
Forks 0
Watchers 4
Open issues 2
Dependencies 2
Contributors 1
Tags 4
Last updated
Last pushed

Top Contributors See all


Packages Referencing this Repo

ComponentSwift brings ComponentKit to swift
Latest release 0.4.1 - Updated - 33 stars

Recent Tags See all

0.4.1 April 01, 2018
0.3 June 18, 2017
0.2 May 24, 2017
0.1 May 21, 2017

Something wrong with this page? Make a suggestion

Last synced: 2018-04-02 06:33:16 UTC

Login to resync this repository