Reputation: 91
I am using the Nexus Rest Api as per my need. i have uploaded the files to my repository. i want to get the repository's latest version like below, for 2 - 3 versions , i can save the details into the array and do my process. if it is going beyond the limitation. that time the save the process will be lengthy one. so please suggest me.
{
"items": [
{
"id": "string",
"repository": "string",
"format": "string",
"group": "string",
"name": "1.0",
"version": "1.0",
"assets": [
{
"downloadUrl": "string",
"path": "string",
"id": "string",
"repository": "string",
"format": "string",
"checksum": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
}
}
]
},{
"id": "string",
"repository": "string",
"format": "string",
"group": "string",
**"name": "2.0",
"version": "2.0",**
"assets": [
{
"downloadUrl": "string",
"path": "string",
"id": "string",
"repository": "string",
"format": "string",
"checksum": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
}
}
]
}
],
"continuationToken": "string"
}
please help me to get the latest version "name": "2.0",
"version": "2.0",.
from my repository.
Thanks.
Upvotes: 1
Views: 569
Reputation: 88
If your question is how to work with json.
struct Response: Codable {
struct Item: Codable {
var id: String
var name: String
var version: String
}
var items: [Item]
}
Decode your json string.
var response: Response?
func decodeResponse() {
guard let jsonData = jsonString.data(using: .utf8),
let decoded = try? JSONDecoder().decode(Response.self, from: jsonData) else {
print("Not Response")
return
}
response = decoded
}
Get highest version
func getHighestVersion() -> String? {
return response?.items.sorted(by: { $0.version > $1.version }).first?.version
}
Upvotes: 1