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'?

Vitaly Stakhov
  • 514
  • 3
  • 15

2 Answers2

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.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • That was my thought until I saw the project with meaningful Object IDs, like 'btnDone'. Can't figure out where that is coming from. – Vitaly Stakhov Jun 11 '15 at 18:08
  • I doubt you have seen a changed objectID. Sure it wasn't the TAG value? – Akaino Jun 11 '15 at 18:09
  • 6
    @Akaino The Swift compiler and [its miniscule “standard library”](https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/SwiftStandardLibraryReference/) may become open source, but Xcode and Interface Builder won't. – rob mayoff Jun 11 '15 at 18:10
  • @Akaino 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. – rob mayoff Jun 11 '15 at 18:10
  • Aye! You are right! My bad. Lumped that together :) – Akaino Jun 11 '15 at 18:11
  • 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. – rob mayoff Jun 11 '15 at 18:11
  • 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. – Sega-Zero Jun 11 '15 at 19:18
  • 2
    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. – ninjaneer Jan 16 '16 at 01:11
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

bBcdd
  • 93
  • 5