I am trying to create a failable initializer for a class. My class will be initialized using input from a network request. Networks being unreliable, I want to create an initializer the checks for the presence on all properties, and for it to fail otherwise.
I am trying to make use of guard here, so please feel free to point any obvious mistakes in the approach:
public class JobModel { let jobId: String let status: String let toName: String let toAddress: String let description: String let fee: Int let jobDate: NSDate let fromName: String let fromAddress: String init?(job: [String:AnyObject]) throws { guard self.jobId = job["jobid"] as! String else { throw InitializationError.MissingJobId } } }
The guard self.jobId
line is failing to compile, with error: Ambiguous reference to member 'subscript'
Any ideas on how to correct this error?