How to make Object ID human-readable?
Asked Answered
I

2

9

Each UIView on a storyboard has a unique Object ID which looks something like: kvf-NI-koG

enter image description here

I'm wondering is there a way to make this more human-friendly, for example 'myLabel'?

Indignity answered 11/6, 2015 at 18:1 Comment(0)
D
6

You cannot change the object ID through Interface Builder.

Xcode uses the object ID in the storyboard (or XIB) file to refer to that object from other objects. Since a storyboard (or XIB) is an XML file, you can also “diff” versions of the file to try to understand (or merge) changes, and the object ID can help you correlate the entities in the file with the objects in Interface Builder.

The public API doesn't expose the object ID. So from your program's point of view, the object ID doesn't even exist.

You can set the view's label (in the text box with placeholder “Xcode Specific Label”). That label is used in the document outline (along the left side of the Interface Builder pane), and when wiring up connections and constraints. But that label is also not exposed to your program in the public API.

Deaver answered 11/6, 2015 at 18:5 Comment(8)
That was my thought until I saw the project with meaningful Object IDs, like 'btnDone'. Can't figure out where that is coming from.Indignity
I doubt you have seen a changed objectID. Sure it wasn't the TAG value?Schlieren
@Schlieren The tag has to be a number. My guess is Vitaly saw a customized object label. I've updated my answer to discuss the label.Deaver
Aye! You are right! My bad. Lumped that together :)Schlieren
I suppose it might be possible to edit the storyboard as XML and change the object ID to whatever string you want. I haven't tried it so I don't know if Xcode requires object IDs to be in a specific format. This seems like a dangerous approach in any serious project.Deaver
renaming the xml is possible, but what's the point of renaming that? it is used only when setting the outlet references/autolayout anchors and localizations. Both of these does not used anywhere else in the code.Rowdyish
I wish we could change the label. I don't like how the generated localization strings file of the story board has these object id's. not good if we need these translated on both iOS and Android.Necking
I found that it can easily set in the xml to any unique string. I need it to write a storyboard file generator in for a project template. It is also nice to synchronize this id with cross platform localizations (when you writing your own tool - because none really exist in. 2023 doing it).Schumann
A
0

Not sure if this still matters - and if it would help at all -, but if You open the storyboard as source code (just select it in the file navigator on the left, right-click, and select Open As -> Source Code): in the XML source code that the storyboard is (originally, before compiling), You can see the object-IDs for each item, and change them in code. This would be reflected in the Interface Builder view of the storyboard (just use Open As -> Interface Builder-Storyboard).

Not sure if this is a wise idea, though! (Not sure of its implications.)

Cheers, Björn

Ascent answered 11/8, 2016 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.