Transfiguration is a solution for creating data driven iOS applications with minimal block of codes. It helps you to represent your data set with reusable views like UITableView, UICollectionView or UIPickerView with minimum effort.
Lets say you have an array with alphabets and you want to represent them in UITableView
.
For doing that with Transfiguration
all you have to do is bind your data with your tableView and attach the view configurations with closures.
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.bind(["A","B","C"]).configure{ view, container, indexPath, data in
view.textLabel?.text = data[indexPath.row].name
}
}
}
Now you want to represent your alphabets array with UICollectionView
.
The necceserry step is pretty much same as the previous with an aditional mentioning of your custom View Type
and size configuration
class CustomCell : UICollectionViewCell { ... }
class ViewController: UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
collectionView.bind(["A","B","C"]).configure(CustomCell.self){ view, container, indexPath, data in
view.setupData(data: data[indexPath.row])
}.size{ container, indexPath, data in
return CGSize(width: 100, height: 100)
}
}
}
Now finally you have a UIPickerView
and you want to populate that with your alphabets array. Lets see the way to do it.
pickerView.bind(["A","B","C"]).title{ container, indexPath, data in
return data[indexPath.row]
}
These are the very basic usage of Transfiguration
. For getting idea about some more complex scenarios please check the Example files.
By wrapping your data with Transfigurable
, you can access all available data operations. It basically sets an observer for your data operations so that you never have to call the reloadData()
or relevent functios from your view layer. You can also controll animations and force reload while executing this operations.
Available Operations |
---|
Append Section |
Insert Section |
Update Section |
Remove Section |
Append Item |
Insert Item |
Update Item |
Delete Item |
Clear All |
The data holder you are binding with your list or grid view must be conformed by Sectionable
. You can make your custom sections by conforming to the Sectionable
protocol. Also for composing different types of data section you can use Ènum
.
class CustomSection: Sectionable {
var header:String?
var footer:String?
var count: Int
}
enum CompositionSections: Sectionable {
case image,video,text
}
Operatable
gives your Sectionable
data some ability for data operations like append, insert, update & remove.
class CustomSection: Sectionable,Operatable {
var data: [String]
}
enum CompositionSections: Sectionable,Operatable { .... }
By conforming to Identifiable
your Sectionable
data can gets a unique identity and priority for precise data operations.
class CustomSection: Sectionable,Operatable,Identifiable {
var identifier: String
var priority: Int?
}
enum CompositionSections: Sectionable,Operatable,Identifiable { .... }
Transfiguration comes with some cool custom layouts for UICollectionView
.
Available Layouts |
---|
UICollectionViewWaterfallLayout |
UICollectionViewTagLayout |
UICollectionViewStackLayout |
UICollectionViewCardLayout |
UICollectionViewGridLayout |
let layout = UICollectionViewWaterfallLayout()
layout.numberOfColumns = 2
let viewController = UICollectionViewController(collectionViewLayout: layout)
let layout = UICollectionViewTagLayout()
layout.scrollDirection = .horizontal
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
Checkout the Example files for the demostration of all custom layouts.
If you already have experience working with UICollectionView
, then you must know that how hard it is to represent dynamic sizeable views with it. Now with a default sizing configuration provided by Transfiguration, working with Collections will be much easy and fun.
collectionView.bind(["A","B","C"]).configure(CustomCell.self){ view, container, indexPath, data in
view.setupData(data: data[indexPath.row])
}.sizingView{ container, indexPath, data in
let view = CustomCell.sizing
view.setupData(data: data[indexPath.row])
return view.contanerView
}
While using the sizing
configuration , please ensure that your view has all required auto layout setup for dynamic height or width. Also it is recommended to use a Static instance of your dynamic cell for better performance.
You can use CocoaPods to install Transfiguration
by adding it to your Podfile
:
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'Transfiguration'
end
You can use Carthage to install Transfiguration
by adding it to your Cartfile
:
github "siam-biswas/Transfiguration"
If you use Carthage to build your dependencies, make sure you have added Transfiguration.framework
to the "Linked Frameworks and Libraries" section of your target, and have included them in your Carthage framework copying build phase.
You can use The Swift Package Manager to install Transfiguration
by adding the proper description to your Package.swift
file:
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/siam-biswas/Transfiguration.git", from: "2.0.0"),
]
)
To use this library in your project manually you may:
- for Projects, just drag all the (.swift) files from (Source\Transfiguration) to the project tree
- for Workspaces, include the whole Transfiguration.xcodeproj
This project is licensed under the terms of the MIT license. See the LICENSE file for details.