ryohei ryohei - 1 year ago 68
iOS Question

Is there any way to access a property like SKSpriteNode in Swift?

I have some experience in

and I am writing code in UIViewController using UIKit library. And I wonder if I could access existing propteries such as ones from
, and so on. In Swift, nodes can be named and called by their names using
childWithName(name: String)
, so is there any way to do this in UIKit. ? I thought doing this would be much more convenienet and my writing would go smooth. I started programming in UIKit so I do not know much about it, so I appreciate if you teach me abou this!


Answer Source

You can't give "names" to UIViews as far as I'm concerned. However, there's something similar.

You can set a view's tag by doing:

someView.tag = 1

Then, assuming that superView is the super view of someView, you can do this to get someView:


It's not as descriptive as name, but you can use named constants to make it clearer:

let scoreLabelTag = 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download