https://github.com/hackiftekhar/iqlistkit
Model driven UITableView/UICollectionView
https://github.com/hackiftekhar/iqlistkit
swift uicollectionview uitableview
Last synced: 5 months ago
JSON representation
Model driven UITableView/UICollectionView
- Host: GitHub
- URL: https://github.com/hackiftekhar/iqlistkit
- Owner: hackiftekhar
- License: mit
- Created: 2020-12-30T13:30:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-18T08:30:47.000Z (10 months ago)
- Last Synced: 2025-04-06T04:36:20.699Z (9 months ago)
- Topics: swift, uicollectionview, uitableview
- Language: Swift
- Homepage:
- Size: 9.84 MB
- Stars: 63
- Watchers: 7
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π **IQListKit**
Model-Driven `UITableView` and `UICollectionView` in Swift





[](https://travis-ci.org/hackiftekhar/IQListKit)
[](http://cocoadocs.org/docsets/IQListKit)
[](https://www.swift.org/)
[]()
---
## π **Why IQListKit?**
IQListKit simplifies working with `UITableView` and `UICollectionView` by eliminating the need to implement `dataSource` methods manually. Just define your sections, models, and cell types β IQListKit takes care of the rest, including:
β
Automatic diffing and animations
β
Clean and reusable code
β
Single API for both `UITableView` and `UICollectionView`
---
## π― **Features**
- β
**Unified API** β Works with both `UITableView` and `UICollectionView`
- β
**Diffable Data Source** β Smooth animations and state updates
- β
**Declarative Syntax** β Cleaner and more concise code
- β
**Custom Headers/Footers** β Easy to implement and manage
- β
**Reusable Cells** β No more `dequeueReusableCell` hassles
---
## π **Requirements**
| Version | Swift | iOS Target | Xcode Version |
|---------|-------|------------|---------------|
| IQListKit 1.1.0 | Swift 5.7+ | iOS 9.0+ | Xcode 11+ |
| IQListKit 4.0.0+ | Swift 5.7+ | iOS 13.0+ | Xcode 14+ |
| IQListKit 5.0.0+ | Swift 5.7+ | iOS 13.0+ | Xcode 14+ |
---
## π¦ **Installation**
### βΆοΈ **Swift Package Manager**
1. Open Xcode β File β Add Package Dependency
2. Enter URL:
```
https://github.com/hackiftekhar/IQListKit.git
```
3. Select the version and install.
### βΆοΈ **CocoaPods**
Add to your `Podfile`:
```ruby
pod 'IQListKit'
```
### βΆοΈ **Manual Installation**
1. Clone the repository.
2. Drag and drop the `IQListKit` folder into your project.
---
## π οΈ **How to Use IQListKit**
Letβs build a user list in **5 simple steps**!
### **1οΈβ£ Create a Model**
Make sure your model conforms to `Hashable`:
```swift
struct User: Hashable {
let id: Int
let name: String
}
```
### **2οΈβ£ Create a Cell**
Create a cell that conforms to `IQModelableCell`:
```swift
class UserCell: UITableViewCell, IQModelableCell {
@IBOutlet var nameLabel: UILabel!
struct Model: Hashable {
let user: User
}
var model: Model? {
didSet {
nameLabel.text = model?.user.name
}
}
}
```
### **3οΈβ£ Set Up the List**
Create a `list` in your `UIViewController`:
```swift
class UsersViewController: UIViewController {
private lazy var list = IQList(listView: tableView, delegateDataSource: self)
private var users = [User(id: 1, name: "John"), User(id: 2, name: "Jane")]
override func viewDidLoad() {
super.viewDidLoad()
loadData()
}
}
```
### **4οΈβ£ Provide Data**
Provide data directly to `IQListKit`:
```swift
func loadData() {
list.reloadData { [users] builder in
let section = IQSection(identifier: "Users")
builder.append([section])
let models: [UserCell.Model] = users.map { .init(user: $0) }
builder.append(UserCell.self, models: models, section: section)
}
}
```
### **5οΈβ£ Handle Selection**
Handle user selection easily:
```swift
extension UsersViewController: IQListViewDelegateDataSource {
func listView(_ listView: IQListView, didSelect item: IQItem, at indexPath: IndexPath) {
if let model = item.model as? UserCell.Model {
print("Selected user: \(model.user.name)")
}
}
}
```
---
## π§° **Using the Wrapper Class**
If you would like to display a **single-section list** of similar objects in a `UITableView` or `UICollectionView`, IQListKit provides a convenient `IQListWrapper` class to handle all the boilerplate code for you.
### βΆοΈ **Setup with IQListWrapper**
You can set up `IQListWrapper` in just a few lines of code:
```swift
class UsersViewController: UIViewController {
@IBOutlet var tableView: UITableView!
private lazy var listWrapper = IQListWrapper(listView: tableView,
type: UserCell.self,
registerType: .nib,
delegateDataSource: self)
private var users = [User(id: 1, name: "John"), User(id: 2, name: "Jane")]
override func viewDidLoad() {
super.viewDidLoad()
loadData()
}
func loadData() {
listWrapper.setModels(users, animated: true, completion: nil)
}
}
```
The `IQListWrapper` class reduces complexity by handling the setup and data binding automatically, making it ideal for quick implementations!
---
## π **Documentation**
- [Delegate, DataSource and Cell Configuration Guide](https://github.com/hackiftekhar/IQListKit/blob/master/Documents/Delegate_DataSource_Guide.md)
- [Workaround Guide](https://github.com/hackiftekhar/IQListKit/blob/master/Documents/Workarounds.md)
- [IQListKit Presentation](https://raw.githubusercontent.com/hackiftekhar/IQListKit/master/Documents/IQListKitPresentation.pdf)
- [Modern Collection View](https://raw.githubusercontent.com/hackiftekhar/IQListKit/master/Documents/IQListKitWithModernCollectionView.pdf)
---
## π **Best Practices**
- Always handle cell reuse correctly to avoid glitches.
- Use lightweight models for better memory usage.
## β€οΈ **Contributions**
Contributions are welcome!
- Report issues
- Submit pull requests
- Improve documentation
---
## π **License**
IQListKit is distributed under the MIT license.
---
## π¨βπ» **Author**
Iftekhar Qureshi
- GitHub Sponsors: [Support my open-source work](https://github.com/sponsors/hackiftekhar)
- PayPal: [PayPal](https://www.paypal.me/hackiftekhar)
- Buy Me a Coffee: [Support here](https://www.buymeacoffee.com/hackiftekhar)
- Twitter: [@hackiftekhar](https://twitter.com/hackiftekhar)
- Website: [hackiftekhar.com](https://hackiftekhar.com)
---
### βοΈ **Star the repo on GitHub if you like it!**