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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -