Swift self in static method -


i want use self in static method class type, i'm getting compile time error.

here test code:

protocol jsonmappable {     static func map(json: anyobject!) -> self }  class model : jsonmappable, mappable {        required init?(_ map: map){      }      func mapping(map: map) {      }      static func map(json: anyobject!) -> self {         return mapper<self>().map(json)     }    } 

so in static method map want use self class type, tried self.type, i'm getting same error. don't want use class name, because need method use subclass class name when called on subclass. example if have:

class subclass : model {  } 

and call:

subclass.map(json) 

i need have subclass in method instead of model. i'm wonder if possible do?

protocol {     static func f()->self } // class should conform protocol a, returned type should b final class b: {     static func f() -> b {         return b()     } }  let b = b() let c = b.f() 

i don't see practical usage, because final class not subclassed , implemet protocol, class should declared final

by way, means same

protocol {     static func f()->self }  final class b: {     class func f() -> b {         return b()     } } 

without static

protocol {     func f()->self }  class b: {     func f()->self {         return self     } } let = b() let b = a.f() 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -