Reputation: 9419
I connected a view which belongs to a view controller to a custom class via an IBOutlet
declaration.
Then, in the viewDidLoad
method I declare a variable and I use the variable to connect myView
with the class myClass
.
var myConnectedView = myView as! myClass
Though, this code returns a runtime error: Could not cast value of type 'UIView'
. I seem to find no way to assign a UIView
to a class.
Question
How do I assign a UIView
to a UIView
class?
Upvotes: 1
Views: 600
Reputation: 25
From the Storyboard interface go to the Utility sidebar which is to the right side of the screen. Click the third tab also known as Identity Inspector and change the class for the UIView
. Be sure to click the view object to edit its respective class (in your case, myClass
).
Upvotes: 2
Reputation: 427
In the Storyboard interface you can set the class of the UIView
. If you head over into the Utilities panel you can find an option where you can modify the class of the UIView
.
Right now it says UIView
(this is default). You have to set it there to myClass
if this is a class that inherits from a UIView
.
Right now the view is assigned to the UIView
class.
Upvotes: 2