Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify nested custom view class?

Available nested classes SuperView and NestedView.

class SuperView : UIImageView {

    class NestedView : UIImageView {
        var text : String = "Nested View"
    }

    var text : String = "Super View"
    var nested : NestedView?

}

I would like to set for a UIImageView the property named "Custom Class Name" to value "NestedView" inside the inspector of the storyboard scene. But the Interface Builder couldn't find "NestedView" class.

enter image description here

like image 569
Sibear Avatar asked Mar 15 '15 20:03

Sibear


1 Answers

At this time, I think that Interface Builder only recognizes the names of Objective-C classes. You can still make Interface Builder find a nested class with the @objc keyword:

class SuperView: UIView {
  @objc(SVNestedView) class NestedView: UIImageView {
  }
}

Then, in Interface Builder, specify that th view is of class SVNestedView. Since Objective-C isn't namespaced, you still need to pick unique names for each nested class, but at least the Swift side is properly namespaced.

like image 186
Rudedog Avatar answered Oct 17 '22 01:10

Rudedog