kakaopensource / KakaJSON

Fast conversion between JSON and model in Swift.
MIT License
1.16k stars 124 forks source link

Optional<Model>没有JSONString方法 #4

Closed Adrift001 closed 5 years ago

Adrift001 commented 5 years ago
        struct Model: Convertible {
            var coordinate: [[Double]] = []
        }
        let json = [
            "coordinate": [
                [1.0, 2.0],
                [3.0, 4.0],
                [5.0, 6.0]
            ]
        ]
        let model = json.kk.model(Model.self) //model 是 Model?类型, Opetional没有JSONString()方法
        print(model.kk.JSONString()) //Value of type 'KKGeneric<Model?, Model>' has no member 'JSONString'
        if let model = json.kk.model(Model.self) {
            print(model.kk.JSONString()) //这个正常
        }
CoderMJLee commented 5 years ago

这是Swift语法问题哦,你是可选类型哈,调用东西需要加问号?

model?.kk.JSON()
model?.kk.JSONString()
Adrift001 commented 5 years ago

我点coordiante会自动补充?,为什么点kk就不自动补充了?😄

CoderMJLee commented 5 years ago

我这边也可以给可选类型也增加kk功能哈,下一个版本有可能可以增加,这样你可以少敲1个问号

Adrift001 commented 5 years ago

都习惯xcode自动补充问号了