简体   繁体   English

为什么可解码结构不符合自定义结构变量

[英]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.嘿伙计们,我是 swift plz go 的新手:),试图采用自定义变量以符合可解码的要求。

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
    
}

You made a mismatch with a name of the properties and types.您与属性和类型的名称不匹配。 I mean that line let pa.pageIdString: extracting .我的意思是那一行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 .如果你声明一个常量,那么你应该有约定let name: Type And if you want to assign the value it looks like that let name: Type = value .如果你想分配值,它看起来像let name: Type = value

I would recommend to read The Swift Basics .我建议阅读Swift 基础知识

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM