Monday, August 14, 2023
HomeiOS Developmentios - DOWNCASTING IN SWIFT

ios – DOWNCASTING IN SWIFT


I’ve a difficulty utilizing Swift. I’ve a category:

class ClassA : UIView{

    override public init(body: CGRect) {
        tremendous.init(body: body)
    }
    
    required public init?(coder aDecoder: NSCoder) {
        tremendous.init(coder: aDecoder)
    }

    init(from uiview: UIView) {
        tremendous.init(body: .zero)
    }

}

Then I’ve one other class PageViewer

class PageViewer: UIView{

    var values : [ClassA]?
    var location: Int = 0

    public func check(){
        for i in 0..<values!.depend {
            location = i
            values![i] = self.subviews[location] as! ClassA
        }
    }
}

downside:
I am attempting so as to add UIViews as sub-views to the pageviewer however I am getting a run time exception on this line values![i] = self.subviews[location] as! ClassA saying Couldn't forged worth of kind 'UIView' to 'MyTestApp.ClassA. I wish to know if there’s a doable workaround for this.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments