// // FilePath.swift // Freetime // // Created by Ryan Nystrom on 12/3/17. // Copyright © 2017 Ryan Nystrom. All rights reserved. // import Foundation struct FilePath { static private let joiner = "/" let components: [String] var baseComponents: [String]? { let count = components.count guard count > 1 else { return nil } return Array(components[0.. 1 { return components.last } else { return nil } } func appending(_ component: String) -> FilePath { return FilePath(components: components + [component]) } } // MARK: - FilePath (BinaryFile) - extension FilePath { private static let supportedBinaries = [ "pdf": "application/pdf" ] // MARK: Public API /// A Boolean value indicating whether a string has binary file suffix. /// /// Supported types: **pdf**. var hasBinarySuffix: Bool { return binarySuffix != nil } /// Returns mime type for the supported binary files. var mimeType: String? { guard let type = binarySuffix else { return nil } return FilePath.supportedBinaries[type] } // MARK: Private API private var binarySuffix: String? { return FilePath.supportedBinaries.keys.first(where: { path.hasSuffix($0) }) } }