0

In my storyboard I define a key value for my viewController as shown:

InterfaceBuilder

How can I retrieve the value of this key path in viewDidLoad on Swift 4?

Please read "category" not "catAgory" ;-)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sébastien REMY
  • 2,399
  • 21
  • 39

2 Answers2

2

I found solution, thank you for your help

class MyViewController: UIViewController {

@objc var category: String = "undefined"

override func viewDidLoad() {
    super.viewDidLoad()
    print ("cat", category)
}

}

This code print "service" in the console. Don't forget @objc in your property declaration.

Sébastien REMY
  • 2,399
  • 21
  • 39
0

You didn't get the point of user defined runtime attributes. These attributes are the properties of an UIKit object defined in interface builder rather than in the code. The thing you wrote is nonsense because you need to set properties which ALREADY are defined by UIKit. For example it is completely okay to write on UIView in defined runtime attributes this:

layer.cornerRadius| Number | 10

because UIView has property layer, which has property cornerRadius, you are able to set it to your custom value during runtime...

But to simply answer your question: You cannot, you have to subclass your UIKit Object, add this property to it in code and then you can set this up in user defined runtime attributes AND in your code.

see these links:

link1 link2

Dominik Bucher
  • 2,120
  • 2
  • 16
  • 25