Я пытаюсь инициализировать свою структуру NewPost в расширении, но не могу этого сделать. Я не вижу никаких очевидных ошибок / проблем с кодом. Когда я пишу self.init ( Xcode не тянет структуру, как я ожидал) Кто-нибудь может помочь?
import Foundation
protocol DocumentSerialisable {
init?(dictionary:[String:Any])
}
struct NewPost {
var caption : String
var username : String
var location : String
var timestamp : Date
var dictionary:[String:Any] {
return [
"caption" : caption,
"username" : username,
"location" : location,
"timestamp" : timestamp
]
}
}
extension NewPost: DocumentSerialisable {
init?(dictionary: [String : Any]) {
guard let caption = dictionary["caption"] as? String,
let username = dictionary["username"] as? String,
let location = dictionary["location"] as? String,
let timestamp = dictionary["timestamp"] as? Date else {return nil}
//this were i cannot perform the following: self.init(caption: ..., username: ..., location: ..., timestamp: ...)
}
}