ios - Swift: Check has a protocol and use getter Like you would in Java -
i wondering if possible check if class conforms protocol in swift.
i have entityobject class, contains basic functionality in java i'd make abstract since swift doesn't abstraction i'm running this.
i have entity protocol requires getter path property (which not exist returns path in our api).
now in entityobject class extended (otherwise fatalerror's in face). want path entityobject not conform entity protocol it's children in cases.
example path getter:
class var path:string {get { return "blog/{blogid}/comments" } }
the getters not show in mirror using reflect() because it's class(static) var, , tried like:
if let entity = self as? entity { return entity.path }
but returns instance of entity (i guess) since i'm not allowed use path here or see of options.
anyone know if generically?
since property wanted invoke not instance, type property couldn't instance, dynamictype property let me. in case be.
if let path = self.dynamictype.valueforkey("path") as? string { return path }
this fetch path var string if there. making entire function:
func getpath() -> string? { if let path = self.dynamictype.valueforkey("path") as? string { return path } errorclass.log("path not implemented on \(self), not inherit entity?") return nil }
Comments
Post a Comment