Search code examples
iosswiftstoryboard

IOS Storyboard serialization


I am pretty new to IOS development and ran into few questions.

Assumption: When I use storyboards and I create view in it, storyboard creates a view via init(frame: CGRect) then it serializes it and creates some file that contains this info. When app is launched on a device it uses this serialized data to create objects via init(coder: NSCoder)

Is my assumption correct or I am missing something ?


Solution

  • Yes, your assumption is correct. Almost. During compilation, Xcode will create a .nib file for each "view controller scene" in the storyboard. The name of the .nib file can be seen by the "object id" property. The nib files are then deployed with your app package.

    The .nib file contains - among other stuff - the serialized UIView hierarchy, which will be deserialized at run time by the init(coder:) initializer.

    Btw., When using .xib files, Xcode will create a .nib file for each .xib file.