мне было интересно, как я могу получить эти данные из возврата GIST, чтобы отобразить на экране? com/GIST/95FCF71EB72F2EA1E3836D192C788EBC)
Код: Выделить всё
{
"url": "https://api.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc",
"forks_url": "https://api.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc/forks",
"commits_url": "https://api.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc/commits",
"id": "95fcf71eb72f2ea1e3836d192c788ebc",
"node_id": "MDQ6R2lzdDk1ZmNmNzFlYjcyZjJlYTFlMzgzNmQxOTJjNzg4ZWJj",
"git_pull_url": "https://gist.github.com/95fcf71eb72f2ea1e3836d192c788ebc.git",
"git_push_url": "https://gist.github.com/95fcf71eb72f2ea1e3836d192c788ebc.git",
"html_url": "https://gist.github.com/95fcf71eb72f2ea1e3836d192c788ebc",
"files": {
"gist.swift": {
"filename": "gist.swift",
"type": "text/plain",
"language": "Swift",
"raw_url": "https://gist.githubusercontent.com/arjdev69/95fcf71eb72f2ea1e3836d192c788ebc/raw/60db0c3f01cffdd56bcfd3474d19d533c02dc0f2/gist.swift",
"size": 2534,
"truncated": false,
"content": "//\n// SceneDelegate.swift\n//"
}
},
"public": true,
"created_at": "2021-04-21T00:48:19Z",
"updated_at": "2021-04-21T01:31:18Z",
"description": "Ios Gist App",
"comments": 1,
"user": null,
"comments_url": "https://api.github.com/gists/95fcf71eb72f2ea1e3836d192c788ebc/comments"....continue
}
import UIKit
struct GistModel: Decodable {
let id:String;
var files:String;
let created_at:String;
let updated_at:String;
let comments:Int;
enum CodingKeys: String, CodingKey {
case files
case created_at
case updated_at
case comments
case id
}
}
struct GistList: Decodable {
let all: [GistModel]
enum CodingKeys: String, CodingKey {
case all
}
}
< /code>
api: < /p>
func getGistById(_ id:String, completion:@escaping(_ data:GistModel) -> Void){
guard let url = URL(string: urlService + "\(id)") else {return}
let request = AF.request(url)
request.responseDecodable(of: GistModel.self) { (response) in
print(response)
guard let gist = response.value else { return }
completion(gist)
}
}
< /code>
У меня проблемы с декодированием ответа, особенно атрибут «файлы». < /p>
Вот ошибка: < /p>
failure(alamofire.aferror.responseserializationFailed(Reason: alamofire.aferror.responseserializationFailerReureseSess.decodingFailed (error: swift.decodingerror.typemismatch (swift.string, swift.decoder Codingkeys (StringValue: «Files», IntValue: NIL)], DebugDescription: «Ожидается, что вместо этого обнаружил словарь.», BoodshyingError: nil)))))
Подробнее здесь: https://stackoverflow.com/questions/671 ... thub-swift
Мобильная версия