Latest 0.1.4
Homepage https://github.com/MohamedMatloub/UIBinder
License MIT
Platforms ios 8.0
Dependencies AlamofireImage
Authors

BuddyBuild
Version
License
Platform

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.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

See the code snippet below for an example of how to implement, or see the example project.

ViewController

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)

TableViewController

you can bind each object in array for the right cell using

  cell.bindSubviewsWith(arr[indexPath,row])

UIImageView

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

Download Method

now after you pass the value of url to image either by using completeUrl or param
it’s time to download it

Default

UIBinder rely on AlamofireImage in downloading image so if you provide imageView with url that has image directly
UIBinder will download it for you .

Custom Download

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 .
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)
How to set ImageDownloadListener and ImageDownloadDelegate to imageView

1- done seperatly to each UIViewController

  • in storyBoard you connect them using outlets in UIImageView
  • in viewController class
      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()

Image Caching

UIBInder use AlamofireImage ImageCaching

Supperted UIViews till now

  • UILabel
  • UITextView
  • UITextField
  • UIImageView

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)
                }

            }
        }
    }

}

Requirements

Installation

UIBinder is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "UIBinder"

Author

MohamedMatloub, [email protected]

License

UIBinder is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "UIBinder",
    "version": "0.1.4",
    "summary": "UIBinder is library that can help in binding object to view dynamically.",
    "description": "UIBinder is library that can help in binding object to view dynamically.",
    "homepage": "https://github.com/MohamedMatloub/UIBinder",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "MohamedMatloub": "[email protected]"
    },
    "source": {
        "git": "https://github.com/MohamedMatloub/UIBinder.git",
        "tag": "0.1.4"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "UIBinder/Classes/**/*",
    "dependencies": {
        "AlamofireImage": [
            "~> 3.1"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This