swift - Non-failable initializer requirement cannot be satisfied by failable initializer -


i have struct , want init failable because go wrong json dictionary pass:

struct adminmodel:interface{  var status:any = "" var l:string = "" var p:string = "" var url:string = ""  init?(json:nsdictionary){      if let status = json["status"] as? any,        let l = json["l"] as? string,        let p = json["p"] as? string,        let url = json["url"] as? string     {         self.status = status         self.l = l         self.p = p         self.url = url     }else{         return nil     } } 

}

there's no issue until add ? after init make init failable: @ point xcode complains:

non-failable initializer requirement 'init(json:)' cannot satisfied failable initializer ('init?')

why struct can't failable? should declare failable protocol init?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -