Home
This wiki is divided into 5 part:
- Introduction
- Artisan Plan - repo page
- Artisan Bonding - repo page
- Artisan Mediator AKA ViewModel - wiki page
- Artisan Extra Features - wiki page
- Tutorial
- Reference
Artisan is created as a complement of UIKit
so it could be used with a more modern approach.
Some problems which Artisan try to eliminate are:
- many of Storyboard problem
- UI change difficulties with XIB and Storyboard
- debug difficulties with XIB and Storyboard
Some features which Artisan provide are:
- DSL UI layouting
- UI data binding
- base framework for MVVM architecture
Artisan Plan - repo page
Artisan Plan is Artisan way to build a NSLayoutConstraints
. It's powered by Draftsman
Instead of doing this:
myView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(myView)
NSLayoutConstraint.activate([
myView.topAnchor.constraint(equalTo: view.topAnchor),
myView.leftAnchor.constraint(equalTo: view.leftAnchor),
myView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
myView.rightAnchor.constraint(equalTo: view.rightAnchor)
])
We could do this:
planContent {
myView.plan
.top(.equal, to: .parent)
.left(.equal, to: .parent)
.bottom(.equal, to: .parent)
.right(.equal, to: .parent)
}
or even shorter:
planContent {
myView.plan
.edges(.equal, to: .parent)
}
you could read more about Draftsman here
Artisan Bonding - repo page
Artisan Bonding is UI data binding mechanism that Artisan have. Its powered by Pharos
Lets say you have UISearchBar
and want to bind the search phrase into String
variable named searchPhrase
:
class MyViewController: UIViewController {
lazy var searchBar: UISearchBar = .init()
var searchPhrase: String?
...
...
...
}
You could do this to make your searchPhrase
always changing according to the searchBar.text
and if you assign any text to searchPhrase
, it will change searchBar.text
too.
class MyViewController: UIViewController {
lazy var searchBar: UISearchBar = .init()
@Observable var searchPhrase: String?
func bindSearchPhrase() {
$searchPhrase.bonding(with: searchBar.bondableRelays.text)
}
...
...
...
}
You can even observe the change and run something for every change:
class MyViewController: UIViewController {
lazy var searchBar: UISearchBar = .init()
@Observable var searchPhrase: String?
func bindSearchPhrase() {
$searchPhrase.bonding(with: searchBar.bondableRelays.text)
.whenDidSet(invoke: self, method: MyViewController.searchPhraseDidChange(for:))
}
func searchPhraseDidChange(_ changes: Changes<String?>) {
print(changes.old ?? "nil")
print(changes.new ?? "nil")
}
...
...
...
}
you could read more about Pharos here
Artisan Mediator AKA ViewModel - wiki page
Artisan Mediator is the base for View Model in MVVM Architecture that Artisan has. There is three types of abstract Mediator that you could use:
- ViewMediator
- CollectionViewCellMediator
- TableViewCellMediator
Mediator has a method that will be called every time this View Model bonded with any View. the method is func bonding(with view: View)
. You could do Artisan Bond here, or anything every time View is bonded with this View Model:
class MyFragmentVM: ViewMediator<MyFragment> {
@Observable var image: UIImage?
@Observable var titleText: String?
@Observable var subTitleText: String?
override func bonding(with view: MyFragment) {
$image.bonding(with: view.image, \.image)
$titleText.bonding(with: view.title, \.text)
$subTitleText.bonding(with: view.subTitle, \.text)
}
}
ViewMediator
generic View
could be matched with any NSObject
, but it's better to match it with any type of UIViewController
or UIView
which extends Fragment
.
CollectionViewCellMediator
generic Cell
could be matched with any UICollectionViewCell
, but it's better to match it with CollectionFragmentCell
which will give you more features instead of using basic UICollectionViewCell
.
TableViewCellMediator
generic Cell
could be matched with any UITableViewCell
, but it's better to match it with TableFragmentCell
which will give you more features instead of using basic UITableViewCell
.
you could read more about Artisan Mediator here
Artisan Extra Features - wiki page
Artisan has extra features which are:
- UICollectionView default data source manager
- UITableView default data source manager
- Many UIKit extensions
- And more
You could read about all of these features here
Coming soon
Coming soon