How to pass arguments from one class into a UIView class? Swift
<p>I have a <code>UIView</code> class in my app which plots a line graph. In there, I assign my <code>graphPoints</code> variables like so : </p>

<pre><code>var graphPoints:[Int] = [1,2,3,5,7,9]
var graphPoints2:[Int] = [1,2,3,5,7,9]
</code></pre>

<p>What I want to do is pass an array of <code>Int</code> from another class and assign those variables, but I am not sure how to do it. Initially i put all my code into one <code>func</code> with <code>array [Int]</code> as parameters and called it from another class but it stopped plotting the graph altogether. How do i do this?</p>

<p>Here is my <code>UIVIew</code> <code>GraphPlotter</code> class code :</p>

<pre><code>import UIKit

@IBDesignable class GraphPlotter: UIView {

var graphPoints:[Int] = [1,2,3,5,7,9]
var graphPoints2:[Int] = [1,2,3,5,7,9]

//1 - the properties for the gradient
var startColor: UIColor = UIColor.redColor()
var endColor: UIColor = UIColor.greenColor()

override func drawRect(rect: CGRect) {

    let width = rect.width
    let height = rect.height

    //set up background clipping area
    let path = UIBezierPath(roundedRect: rect,
        byRoundingCorners: UIRectCorner.AllCorners,
        cornerRadii: CGSize(width: 8.0, height: 8.0))
    path.addClip()

    //2 - get the current context
    let context = UIGraphicsGetCurrentContext()
    let colors = [startColor.CGColor, endColor.CGColor]

    //3 - set up the color space
    let colorSpace = CGColorSpaceCreateDeviceRGB()

    //4 - set up the color stops
    let colorLocations:[CGFloat] = [0.0, 1.0]

    //5 - create the gradient
    let gradient = CGGradientCreateWithColors(colorSpace,
        colors,
        colorLocations)

    //6 - draw the gradient
    var startPoint = CGPoint.zero
    var endPoint = CGPoint(x:0, y:self.bounds.height)
    CGContextDrawLinearGradient(context,
        gradient,
        startPoint,
        endPoint,
        [])

    //calculate the x point

    let margin:CGFloat = 40.0
    let columnXPoint = { (column:Int) -&gt; CGFloat in
        //Calculate gap between points
        let spacer = (width - margin*2 - 4) /
            CGFloat((self.graphPoints.count - 1))
        var x:CGFloat = CGFloat(column) * spacer
        x += margin + 2
        return x
    }

    // calculate the y point

    let topBorder:CGFloat = 60
    let bottomBorder:CGFloat = 50
    let graphHeight = height - topBorder - bottomBorder
    let maxValue = graphPoints2.maxElement()!
    let columnYPoint = { (graphPoint2:Int) -&gt; CGFloat in
        var y:CGFloat = CGFloat(graphPoint2) /
            CGFloat(maxValue) * graphHeight
        y = graphHeight + topBorder - y // Flip the graph
        return y
    }

    // draw the line graph

    UIColor.flatTealColor().setFill()
    UIColor.flatTealColor().setStroke()

    //set up the points line
    let graphPath = UIBezierPath()
    //go to start of line
    graphPath.moveToPoint(CGPoint(x:columnXPoint(0),
        y:columnYPoint(graphPoints2[0])))

    //add points for each item in the graphPoints array
    //at the correct (x, y) for the point
    for i in 1..&lt;graphPoints.count {
        let nextPoint = CGPoint(x:columnXPoint(i),
            y:columnYPoint(graphPoints2[i]))
        graphPath.addLineToPoint(nextPoint)

    }

    //Create the clipping path for the graph gradient

    //1 - save the state of the context (commented out for now)
    CGContextSaveGState(context)

    //2 - make a copy of the path
    let clippingPath = graphPath.copy() as! UIBezierPath

    //3 - add lines to the copied path to complete the clip area
    clippingPath.addLineToPoint(CGPoint(
        x: columnXPoint(graphPoints.count - 1),
        y:height))
    clippingPath.addLineToPoint(CGPoint(
        x:columnXPoint(0),
        y:height))
    clippingPath.closePath()

    //4 - add the clipping path to the context
    clippingPath.addClip()

    let highestYPoint = columnYPoint(maxValue)
    startPoint = CGPoint(x:margin, y: highestYPoint)
    endPoint = CGPoint(x:margin, y:self.bounds.height)

    CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, [])
    CGContextRestoreGState(context)

    //draw the line on top of the clipped gradient
    graphPath.lineWidth = 2.0
    graphPath.stroke()

    //Draw the circles on top of graph stroke
    for i in 0..&lt;graphPoints.count {
        var point = CGPoint(x:columnXPoint(i), y:columnYPoint(graphPoints2[i]))
        point.x -= 5.0/2
        point.y -= 5.0/2


        let circle = UIBezierPath(ovalInRect:
            CGRect(origin: point,
                size: CGSize(width: 5.0, height: 5.0)))
        circle.fill()
        let label = UILabel(frame: CGRectMake(0, 0, 200, 21))
        label.center = CGPointMake(160, 284)
        label.textAlignment = NSTextAlignment.Center
        //            label.text = "I'am a test label"
        self.addSubview(label)
    }



    //Draw horizontal graph lines on the top of everything
    let linePath = UIBezierPath()

    //top line
    linePath.moveToPoint(CGPoint(x:margin, y: topBorder))
    linePath.addLineToPoint(CGPoint(x: width - margin,
        y:topBorder))

    //center line
    linePath.moveToPoint(CGPoint(x:margin,
        y: graphHeight/2 + topBorder))
    linePath.addLineToPoint(CGPoint(x:width - margin,
        y:graphHeight/2 + topBorder))

    //bottom line
    linePath.moveToPoint(CGPoint(x:margin,
        y:height - bottomBorder))
    linePath.addLineToPoint(CGPoint(x:width - margin,
        y:height - bottomBorder))
    let color = UIColor.flatTealColor()
    color.setStroke()

    linePath.lineWidth = 1.0
    linePath.stroke()

}

}
</code></pre>

<p>DBController, func dosmth where I pass the array :</p>

<pre><code>    func dosmth(metadata: DBMetadata!) {

    let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]

    let localFilePath = (documentsDirectoryPath as NSString).stringByAppendingPathComponent(metadata.filename)

    var newarray = [Int]()


    do{

        let data = try String(contentsOfFile: localFilePath as String,
                              encoding: NSASCIIStringEncoding)
        print(data)

        newarray = data.characters.split(){$0 == ","}.map{
            Int(String.init($0).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()))!}


        print(newarray)


    }
    catch let error { print(error) }

   //Probably wrong
    GraphPlotter().graphPoints = newarray
    GraphPlotter().graphPoints2 = newarray

}
</code></pre>