You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
662 B

2 years ago
  1. //
  2. // Data+FileResource.swift
  3. // R.swift.Library
  4. //
  5. // Created by Tom Lokhorst on 2016-03-11.
  6. // From: https://github.com/mac-cain13/R.swift.Library
  7. // License: MIT License
  8. //
  9. import Foundation
  10. public struct NoUrlForResourceError: Error {}
  11. public extension Data {
  12. /**
  13. Creates and returns NSData with the contents of the specified file resource (R.file.*).
  14. - parameter resource: The file resource (R.file.*)
  15. - returns: A NSData object with the contents of the specified file.
  16. */
  17. init(resource: FileResourceType) throws {
  18. guard let url = resource.url() else { throw NoUrlForResourceError() }
  19. try self.init(contentsOf: url)
  20. }
  21. }