I am currently making an app that sends data to an Algorithmia algorithm where it is processed. A response of where to find the file is then sent back to the app in this form:
Optional({
output = "data://.algo/deeplearning/AlgorithmName/temp/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.png";})
I need a way to extract the randomly generated 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.png' section of the response. It needs to be stored in a string which I will use later.
Final code:
if let json = response as? [String: Any] {
print(json)
let filePath = json["output"] as? String
print("File path: \(filePath!)")
let uwFilePath = filePath!
let index = uwFilePath.index(uwFilePath.startIndex, offsetBy: 57)
self.imageFileName = uwFilePath.substring(from: index)
print(self.imageFileName)
}
imageFileName is storing the final file name for later use. The begining part of the output string is also being cut off.