0

this is my code

@IBDesignable class BarPopView: UIView {

    @IBInspectable var ft: NSString = "1"
    @IBInspectable var ffPrompt: NSString = "Area"

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupView()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupView()
    }

    func setupView() {
        print("text: \(ft), prompt: \(ffPrompt)")
    }

}

and i set these value in interface builder
ft: 50 ffPrompt: "Change"

but result is print
"text: 1, prompt: Area"

Water Magical
  • 979
  • 1
  • 9
  • 13

2 Answers2

3

Its because the method setupView is called during initialisation and during that the properties have initial values. If you want to tweak them accordingly , use property observers:

@IBInspectable var ft: String = ""{
        didSet {
            setupView()
        }
    } 
ankit
  • 3,537
  • 1
  • 16
  • 32
  • but i want the func setupView() execute after all the var setting complete – Water Magical Jun 12 '17 at 05:24
  • you can do that by creating an outlet of that view in your custom class and then call it . But remove that setupView method from class initialisation. – ankit Jun 12 '17 at 05:58
2

If u want the

func setupView()

to execute after all the var setting complete, Then call the method in viewDidLoad() of the ViewController class, where you will be using your custom view

BarPopView

sonnet
  • 567
  • 4
  • 6