0

I have a ViewController:

class graphicViewController: UIViewController {
    var pathToFile = "" //it's changed in method PrepareForSegue from previous ViewController
}

and I have a View:

class graphicView: UIView {
   var ltr:String?
   override func drawRect(rect: CGRect) {
      println(ltr!)
   }
}

How and where should I implement access/transfer of variable pathToFile that it must not be null in drawRect?

2
  • 1
    Is graphicView the type view in your graphicViewController ? Commented Oct 21, 2014 at 19:33
  • @Mike, graphicView is the subview of graphicViewController. I can access graphicView like this: graphicViewController.view as graphicView Commented Oct 21, 2014 at 19:54

1 Answer 1

1

Since you're setting your pathToFile property in prepareForSegue, the best place to pass the value of the property on would be would be in graphicViewController's viewDidLoad function:

override func viewDidLoad() {
    if let gView = view as? graphicView {
        gView.ltr = pathToFile
    }
}

Sidenote: Typically you'll want to name your types with a capital letter and your instances with a lower case letter. So, graphicView would be GraphicView, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.