TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jun 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Mohamed Matloub.
UIBinder help you map object to view so you don’t need any more to write
label.text = object.name
textView.text = object.description
textField.text = object.age
UIBinder do all that for you.
To run the example project, clone the repo, and run pod install
from the Example directory first.
See the code snippet below for an example of how to implement, or see the example project.
self.view.bindSubviewsWith( object)
where object is either NSObject or dictionary with the required values to update current view with
In StoryBoard you need to set for the desired view param
where in case object passed in bindSubviewsWith
is dictionary then param
is the key , in case that object is NSObject then param
is the property name
and that’s it when you will run your code you will find the view get updated with right value from object you have passed to it
In case you want to update certain view you can use
view.bindTo(object)
you can bind each object in array for the right cell using
cell.bindSubviewsWith(arr[indexPath,row])
first let’s talk about what you need to set in storyboard
param
it support being String or UIImage in case of UIImage it will be set to ImageView if string the that’s mean it’s url so UIBinder will try to download this image for you
placeHolderImage
represent the image that will be set until image is loaded
errorImage
represent the image that will be set if couldn’t get image set in param
completeUrl
in case you know url that has the image you need you can pass it to completeUrl
now after you pass the value of url to image either by using completeUrl
or param
it’s time to download it
UIBinder rely on AlamofireImage
in downloading image so if you provide imageView with url that has image directly UIBinder will download it for you .
incase you need to customize anything in the download process you can impolement ImageDownloadDelegate
and override
func downloadImageWith(url: String, onSucces completion: @escaping ((UIImage) -> ()), onError errorCompletion: @escaping (UIImage, Error) -> ())
url
: is url that is passed in to imageview in param
or completeUrl
.onsuccess
: you will return image to be set to imageView .onError
: you will pass image to be set to imageView and Error to be passed to ImageDownloadListener
.this is protocol you need to implement in case you need to know when image is downoloaded or failed to be downloaded by implementing
func imageDidDownload(downloadedImage : UIImage)
func imageFailedToDownloadWith(error : Error)
1- done seperatly to each UIViewController
self.imageView.downloadDelegate = CustomDownloadDelegate()
self.imageView.downloadListener = CustomDownloadListener()
2 - done for every image in your app in app delegate
ImageManager.sharedManager.imageDownloadDelegate = CustomImageDownloader()
ImageManager.sharedManager.imageDownloadListener = CustomImageDownloader()
UIBInder use AlamofireImage
ImageCaching
for other unsupported UIViews or custom View you can do it like that
extension UITextView{
override public func bindTo(_ object : NSObject){
// if object is dictionary then you will use
if let dic = object as? NSDictionary {
self.text = self.getStringValueFromDictionary(dic: dic)
return
}
// else first check if param has value not nil then get string represtation of this value
if let param : String = self.param {
if let value = object.getPropertyValueWith(label :param) {
if let v = value as? String {
self.text = v
}else if let text = object.getPropertyValueWith(label :param) {
self.text = String(describing: text)
}
}
}
}
}
UIBinder is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "UIBinder"
MohamedMatloub, [email protected]
UIBinder is available under the MIT license. See the LICENSE file for more info.