Storyboard Custom Class Exists
ID |
swift.storyboard_custom_class_exists |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Swift |
Tags |
reliability, suspicious-code |
Description
Reports elements in .storyboard and .xib files whose customClass
attribute names a Swift class that does not exist anywhere in the
scanned project. Interface Builder resolves customClass at runtime
via NSClassFromString; an unresolved name raises an exception when
UIStoryboard.instantiateViewController is invoked and the app crashes
on the first navigation to that scene.
<viewController customClass="HomeViewController" ... /> <!-- FLAW: class missing -->
<view customClass="MaterialButton" customModule="MaterialComponents"/> <!-- OK: external -->
Rationale
Class renames, file deletions, and copy-paste from other projects
routinely orphan customClass references. The compiler doesn’t know
about Interface Builder bindings, so the bug only surfaces the first
time a user touches that screen — typically in QA, sometimes in
production.
The rule resolves each customClass against the Swift type model
collected by the scanner. Elements that explicitly reference an
external module (a Pod or framework — customModuleProvider != "target")
are skipped because their source code isn’t in the scan view.