swift - How to get some parameter in the child class through the base class -
i'm stuck. try make right code's architect can not solve following case: have base class , inherited class like:
class baseclass { var name: string init(name: string) { self.name = name } } class childclass: baseclass { var othername: string init(othername: string) { self.othername = othername } } and following function:
func somefunc() -> baseclass { let = childclass.init(othername: "name") return } how can parameter "othername"? available parameter 1 - "name", want "othername":
let b = somefunc() b.parameters
you can use:
(b as! childclass).othername your function returns object baseclass object, can't access of childclass methods. in order access childclass methods, need cast object childclass using as!, know childclass object. after you'll able access parameters of childclass.
Comments
Post a Comment