Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

swift reading binary data

func getFile(forResource resource: String, withExtension fileExt: String?) -> [UInt8]? {
    // See if the file exists.    
    guard let fileUrl: URL = Bundle.main.url(forResource: resource, withExtension: fileExt) else {
        return nil
    }

    do {
        // Get the raw data from the file.
        let rawData: Data = try Data(contentsOf: fileUrl)

        // Return the raw data as an array of bytes.
        return [UInt8](rawData)
    } catch {
        // Couldn't read the file.
        return nil
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #swift #reading #binary #data
ADD COMMENT
Topic
Name
2+3 =