I have a class, FooView
, that is a subclass of UIView
, and whose view is loaded from a nib, something like:
+ (instancetype)viewFromNib
Swizzling is not (ever) the answer.
The problem is in your NIB; it is archived with object[0] being an instance of FooView
, not FooSubclassView
. If you want to load the same NIB with a different view subclass as object[0], you need to move the instance out of the NIB's archive.
Probably the easiest thing to do, since your class is already loading the NIB, is make an instance of FooView
or FooSubclassView
the File's Owner.
This question has a decent explanation of the File's Owner pattern. Note that you are pretty much already there in that your class is what is loading the XIB/NIB anyway.
And here is the official docs on File's Owner.