Search code examples
swiftvariablesstructdecodable

why doesn't decodable struct is not conforming of a custom struct variable


hey guys I am newbie to swift plz go easy on me :) , trying to take custom variable to conform to decodable .

struct pa {
    static var pageIdString:String?
}
struct dataModel1:Decodable{
    let query:Page
}
struct Page:Decodable{
    let pages:pagesidextract
}
//error:-  Type 'pagesidextract' does not conform to protocol 'Decodable'
struct pagesidextract:Decodable {
   
    let pa.pageIdString : extracting
//error :- Consecutive declarations on a line must be separated by ';'
//error :-Expected declaration
// error :- Type annotation missing in pattern
    
}


struct extracting:Codable{
    
    let extract:String
    
}

Solution

  • You made a mismatch with a name of the properties and types. I mean that line let pa.pageIdString : extracting. You declare name of the property with . which is disallowed.

    If you declare a constant then you should have convention let name: Type. And if you want to assign the value it looks like that let name: Type = value.

    I would recommend to read The Swift Basics.