Decoding Downloaded Data

I know that using using JSONDecoder we can convert the downloaded JSON data into class/struct object.

Is there a way to do the same for raw data(NSData)/octect. Since downloaded is not a json, I am getting error.

I have class like this

public struct FileData: Codable{ public var data: Data?

public init (data: Data? = nil){ self.data = data }

}

Is there a way to assign the downloaded data to FileData().data via decoding

Can you show an example of the downloaded data? If it is in an original format, you may need to implement init(data:) all by yourself, without using Codable.

Downloaded Data is just NSData(content of a file located in the server)

Downloaded Data is just NSData(content of a file located in the server). Is there a way use Codable as the downloaded data is not in JSON format.

If you want to use the data as Data (or NSData), use the downloaded data as is.

Ok, Is there any way to assign the downloaded to the instance variable of a class via Codable?

Ok, Is. there a way to assign the downloaded data to the instance variable of a class via Codable?

How to achieve via codable?

Decoding Downloaded Data
 
 
Q