← NIB files
NIB·Format guide
All tools

How an app's interface files are stored

Interface Builder documents — .xib files and storyboards — are XML in the source tree. At build time ibtool compiles them into nibs: binary archives of the objects the UI is made of (views, controls, view controllers, constraints) and the connections between them and the code. At run time UIKit (or AppKit) unarchives a nib to create the objects. This page describes both binary encodings as the NIB tool reads them.

Neither encoding is documented by Apple. The NIBArchive layout below matches the reverse-engineered descriptions used by open-source tools and is what the tool implements; the keyed archive is the standard NSKeyedArchiver binary plist.

Contents

  1. .nib vs .storyboardc
  2. The NIBArchive format
  3. Varints
  4. Objects, keys, values, classes
  5. Value types
  6. A worked example
  7. NSKeyedArchiver binary plists
  8. Important keys
  9. Outlet and action connections
  10. Security relevance
  11. What the tool shows, and its limits
  12. The NIB library

1.nib vs .storyboardc

Compiled formSourceContents
Foo.nib (file)Foo.xibOne archive with every object of the xib.
Foo.nib (folder)Foo.xibWhen the xib needs different objects per OS version or device, a folder with runtime.nib and variants such as objects-13.0+.nib; UIKit picks one at load.
Main.storyboardc (folder)Main.storyboardAn Info.plist naming the entry point (UIStoryboardDesignatedEntryPointIdentifier) and mapping view-controller identifiers to nib names (UIViewControllerIdentifiersToNibNames), and one nib per scene: the view controller (UIViewController-BYZ-38-t0r.nib) and, separately, its view (BYZ-38-t0r-view-8bC-Xf-vdC.nib), loaded when the view is first needed.

The odd identifiers (BYZ-38-t0r) are Interface Builder's object IDs from the source document. Segues are compiled into objects inside the view controller's nib. Open each nib of a storyboard separately; the scene's interesting content is usually in the …-view-….nib.

Inside the file, iOS (and current macOS) uses the NIBArchive encoding; older macOS nibs use an NSKeyedArchiver binary plist. The tool recognises both by their first bytes (NIBArchive or bplist). An XML file (<?xml, <document) is an uncompiled xib or storyboard.

2The NIBArchive format

A 50-byte header, then four tables. All fixed-size integers are little-endian u32.

"NIBArchive"+0 · 10 bytes
format+10 · u32
coder+14 · u32
objects+18 · count, offset
keys+26 · count, offset
values+34 · count, offset
class names+42 · count, offset
OffsetSizeFieldMeaning
010magicThe ASCII bytes NIBArchive, no terminator.
104format versionArchive format version (1 in current files).
144coder versionVersion of the UINibEncoder that wrote it (e.g. 9, 10).
18 · 224 · 4object count · offsetObject table.
26 · 304 · 4key count · offsetKey-name table.
34 · 384 · 4value count · offsetValue table.
42 · 464 · 4class count · offsetClass-name table.

Offsets are from the start of the file. The tables are packed one after another, usually in the order objects, keys, values, classes, but a reader should use the offsets.

3Varints

Counts and indices inside the tables are variable-length integers: 7 bits per byte, least significant group first. Unlike LEB128, the high bit is set on the last byte, not on the continuation bytes.

5      = 0b101              →  85
300    = 0b10_0101100       →  2c 82
         2c        = 44           (continuation: high bit clear)
         82 & 0x7f = 2  × 128     (last byte: high bit set)
         44 + 256  = 300
70000  = 0x11170            →  70 22 84     (0x70 + 0x22 × 128 + 0x04 × 16384)

4Objects, keys, values, classes

Every object is an instance of a class and owns a contiguous run of values; every value is a key and a typed payload. Archiving an object writes the values its encodeWithCoder: produces: [coder encodeObject:self.subviews forKey:@"UISubviews"] becomes one value with key UISubviews and an object reference.

TableRecordFields
Objectsvarint × 3class index (into the class-name table) · values start (index of its first value) · value count. Object 0 is the root.
Keysvarint + byteslength, then the key name in UTF-8 (no terminator): UISubviews, UIFrame…
Valuesvarint + byte + payloadkey index · type (one byte, below) · payload, whose size depends on the type.
Class namesvarint × 2 + u32 × n + byteslength · extra count n · n fallback class indices (u32 each) · the name in UTF-8, NUL-terminated (the length includes the NUL).

Fallback classes name other entries of the class table that can stand in when a class is not available at run time. Key and class names are shared: UIView appears once in the class table however many views there are.

Collections and strings

5Value types

TypeMeaningPayload
0int81 byte, signed
1int162 bytes, signed LE
2int324 bytes, signed LE
3int648 bytes, signed LE
4truenone
5falsenone
6float4 bytes, IEEE 754
7double8 bytes, IEEE 754
8datavarint length, then that many bytes (strings' NS.bytes, encoded structs such as rects and points, images)
9nilnone
10object referenceu32: index into the object table

Integers are written in the smallest type that holds them, so a reader must accept all four widths for the same key. Geometry (UIBounds, UICenter, UIFrame) is usually a data value holding packed numbers, not separate keys.

6A worked example

A label with the text "Welcome", decoded from the tables:

classes   #3  len 8, extra 0, "UILabel\0"
          #7  len 9, extra 0, "NSString\0"
keys      #12 "UIText"        #20 "NS.bytes"        #31 "UIHidden"

objects   #42  class 3 (UILabel),  values 310 … 318
          #43  class 7 (NSString), values 319 … 319

values    #314  key 12 (UIText),   type 10, u32 43       → object #43
          #316  key 31 (UIHidden), type 4                → true
          #319  key 20 (NS.bytes), type 8, len 7, "Welcome"

bytes of value #314:   8c  0a  2b 00 00 00
                       │   │   └ object 43
                       │   └ type 10 (object reference)
                       └ key 12 (varint, last byte: high bit set)

So object 42 is a UILabel showing "Welcome" — and it is hidden.

7NSKeyedArchiver binary plists

Older macOS nibs (and many other Apple archives: preferences, NSUserDefaults blobs, state restoration data) are an NSKeyedArchiver archive stored as a binary property list.

Binary plist layout

The file starts with bplist00, then the objects, then an offset table, then a 32-byte trailer: 6 unused bytes, the size of an offset-table entry (u8), the size of an object reference (u8), the object count, the index of the top object and the offset of the offset table (u64 each, big-endian). Each object starts with a marker byte: high nibble the type, low nibble a size (15 = an integer object with the real size follows).

MarkerTypeMarkerType
0x00 · 0x08 · 0x09null · false · true0x5nASCII string, n bytes
0x1ninteger, 2n bytes BE0x6nUTF-16BE string, n characters
0x2nreal, 2n bytes0x8nUID, n+1 bytes
0x33date (float64 seconds since 2001)0xAn · 0xCnarray · set of n object references
0x4ndata, n bytes0xDndictionary: n key refs, then n value refs

The keyed-archive structure

{
  "$archiver": "NSKeyedArchiver",
  "$version":  100000,
  "$top":      { "IB.objectdata": UID(1) },        // "root" in most other archives
  "$objects":  [
    "$null",                                       // index 0 = nil
    { "$class": UID(5), "NSRoot": UID(2), "NSConnections": UID(9), … },
    …
    { "$classname": "NSIBObjectData", "$classes": ["NSIBObjectData", "NSObject"] }
  ]
}

The tool converts both encodings to one model — a list of objects, each with a class and a list of (key, type, value) — so everything below applies to both.

8Important keys

The root object (iOS)

KeyContents
UINibTopLevelObjectsKeyThe top-level objects returned by instantiateWithOwner:options:: the main views, view controllers, gesture recognizers.
UINibObjectsKeyEvery object in the nib.
UINibConnectionsKeyThe outlet and action connections (below).
UINibVisibleWindowsKeyWindows to show on load.
UINibAccessibilityConfigurationsKeyAccessibility settings applied after loading.
UINibKeyValuePairsKeyUser Defined Runtime Attributes: key paths set with setValue:forKeyPath: on objects after loading.

Objects

KeyMeaning
UISubviews · NSSubviewsThe view's children (an array): the view hierarchy. UISuperview points back.
UIClassName · UIOriginalClassNameOn a UIClassSwapper: the custom class set in Interface Builder (LoginButton, _TtC5MyApp9PinView) and the UIKit class it stands in for.
UIProxiedObjectIdentifierOn a UIProxyObject: a placeholder for an object that is not in the nib — IBFilesOwner (the owner passed at load, usually the view controller) or IBFirstResponder.
UIText · UITitle · UIPlaceholderText of labels, text fields, buttons.
UIHidden · UIAlpha · UIOpaqueVisibility.
UIBounds · UICenter · UIFrameGeometry.
UITag · UIRestorationIdentifierInteger tag; identifier for state restoration.
UIAccessibilityLabelThe VoiceOver label, when stored on the object.
NSTitle · NSContents · NSToolTip · NSWindowTitleThe macOS counterparts.

9Outlet and action connections

Connections are how a nib is wired to code. After unarchiving, UIKit runs each connection object's connect:

ClassKeysEffect
UIRuntimeOutletConnectionUILabel, UISource, UIDestinationOutlet: [source setValue:destination forKey:label] — e.g. the File's Owner's passwordField property is set to a text field.
UIRuntimeOutletCollectionConnectionUILabel, UISource, UIDestinationAn outlet collection (an array property).
UIRuntimeEventConnectionUILabel, UISource, UIDestination, UIEventMaskAction: [source addTarget:destination action:@selector(label) forControlEvents:mask] — e.g. a button sends loginTapped: to the view controller on touch-up-inside.
NSNibOutletConnector · NSNibControlConnectorNSLabel, NSSource, NSDestinationmacOS outlet and target/action.
NSNibBindingConnectorNSBinding, NSKeyPath, …macOS Cocoa binding: a property bound to a key path.

The destination of an action, and the source of an outlet, is often the IBFilesOwner proxy, i.e. the view controller. The action's selector is the name of the method to read next: find it in the Mach-O tool's class browser (-[LoginViewController loginTapped:]).

10Security relevance

A nib is data the app trusts completely, and nobody reviews it like code. Things worth looking for:

A nib cannot run code by itself, but unarchiving instantiates arbitrary classes and sets arbitrary key paths. An app that loads nibs (or other keyed archives) from an untrusted source — downloaded, or from a writable location — is an object-injection risk; keyed archives should be decoded with NSSecureCoding and an allow-list of classes.

11What the tool shows, and its limits

The tool reads one nib file at a time: open the individual .nib files inside a .storyboardc or a nib folder, not the folder. It shows the archived keys and values as they are; it doesn't render the interface, decode geometry or colours from their packed data values, or follow layout constraints.

12The NIB library

The parser is lib/nib.js, a JavaScript module with no user interface. It exports the class NibArchive; keyed-archive nibs are binary plists, which it reads with lib/plist.js (imported by the module itself).

import { NibArchive } from "../lib/nib.js";
Method / propertyWhat it does
NibArchive.parse(input)An ArrayBuffer or Uint8Array → a NibArchive, from either encoding. Throws with a sentence when the file is not a compiled nib (and says so for an XML .xib or .storyboard).
archive.format, version, objects, root, countsformat is "NIBArchive" or "NSKeyedArchiver", root the index of the root object, counts is { objects, keys, values, classes } (keys and values are null for keyed archives).
object{ className, values }; keyed archives also mark isNil ($null), isClassDescription (a $classname record) and primitive (a bare string or number).
value{ key, type, value }; type is "int", "float", "bool", "nil", "data" (a Uint8Array), "str", "obj" (an object index) or "arr" (a list of values). A collection's items have the key UINibEncoderEmptyKey.
archive.stringOf(index)The text of a string object (NSString, NSLocalizableString…), or null.
archive.valueString(value)The text a value holds directly, through a string object, or as UTF-8 data; or null.
archive.itemsOf(index)The item values of an NSArray, NSSet, NSOrderedSet or NSDictionary, or null.
archive.topLevelObjects()The indexes of the top-level objects (see above).
archive.connections()[{ index, kind, className, label, source, destination, extra }]: kind is "outlet", "action", "binding", "help", "accessibility" or "other"; source and destination are values (usually "obj").
archive.viewHierarchy(){ children: Map(index → [child index]), roots } from the subviews and window content views.
archive.strings()[{ text, where, owner }]: every string, with "Class.key" and the index of the object it belongs to.
NibArchive.detect(input)"NIBArchive", "keyed", "xml" or null, from the first bytes.
NibArchive.valueFor(object, key)The object's first value with that key, or null.
NibArchive.dataText(bytes)The bytes as text when they are printable UTF-8, otherwise null.
import { NibArchive } from "../lib/nib.js";

const archive = NibArchive.parse(bytes);
for (const connection of archive.connections()) {
	const target = archive.objects[connection.destination.value];
	console.log(connection.kind, connection.label, "→", target.className);
}
console.log(archive.strings().map((item) => item.text));