ryohei ryohei - 4 days ago 5x
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!



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