title: Want to build Bargraph With Delegate and Datasource using protocol
body: <p>I am trying to build one bar graph view, To create delegate and datasource to that graph view. Creating a protocol for delegate and datasource to the graph.</p>
  
  <pre><code>protocol BarGraphDatasource{
      func grapgView(grapgView:BarGraph, numberOfItemsInGraph items:Int)-&gt;Int
      func grapgView(grapgView: BarGraph, didSelectItemAtIndex index: Int)
  }
  </code></pre>
  
  <p>// Bargraph View class is like below</p>
  
  <pre><code>class BarGraph: UIScrollView {
  
  
      var  delegte: BarGraphDatasource! = nil{
  
          didSet{
              self.reloadGraph()
          }
      }
  
       var barWidth : CGFloat = 24 {
  
          didSet{
                  self.reloadGraph()
          }
      }
      var minimumSpacing : CGFloat = 10 {
  
          didSet{
              self.reloadGraph()
          }
      }
  
      var numberOfItems : Int = 0 {
          didSet{
              self.reloadGraph()
          }
      }
       var barColor : UIColor = UIColor.lightGrayColor() {
  
          didSet{
              self.reloadGraph()
          }
      }
  
  
  
      init() {
          super.init(frame: CGRectZero)
          self.reloadGraph()
      }
  
      required init(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)!
      }
      func reloadGraph(){
          self.setContentSizeForGraph()
      }
  
      func setContentSizeForGraph() {
  
          if self.numberOfItems &gt; 0 {
              self.contentSize = CGSizeMake((self.barWidth * CGFloat(self.numberOfItems) + self.minimumSpacing), self.frame.height);
              var xValue:CGFloat = 0
              for i in 1...self.numberOfItems {
                  xValue = xValue + CGFloat(CGFloat(i) + self.minimumSpacing)
                  print("xValue: \(xValue)")
                  let frame = CGRectMake(xValue, 0, self.barWidth, 50)
                  let barView = UIView(frame: frame)
                  barView.backgroundColor = self.barColor
                  self.addSubview(barView)
              }
          }
      }
  }
  </code></pre>
  
  <p>// This is my ViewController class </p>
  
  <pre><code>class ViewController: UIViewController,BarGraphDatasource {
  
      @IBOutlet weak var grapView :  BarGraph?
  
      var arrayItems: NSArray = []
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          arrayItems = [1,2,3,4,5]
          grapView?.barWidth = 10;
          grapView?.delegte = self;
  
          grapView?.reloadGraph()
      }
  
  
      func grapgView(grapgView: BarGraph, numberOfItemsInGraph items: Int) -&gt; Int {
          return arrayItems.count // how can i pass this value to the graph view from here       ******* 
      }  
      func grapgView(grapgView: BarGraph, didSelectItemAtIndex index: Int) {
          print(arrayItems[index]) // how can i call this method on click of bar view       ******* 
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
  }
  </code></pre>
  
  <p>// Here i am unable to get the graph and not calling protocol methods in ViewController class</p>
  
  <p><strong>numberOfItemsInGraph</strong> when we are setting this i want pass this value to BarGraph in graph</p>
  
  <p><strong>didSelectItemAtIndex</strong> how to give the action to selected item</p>