Created
April 17, 2019 00:27
-
-
Save qmchenry/89dd60beb19c19682d9fd6708a7746db to your computer and use it in GitHub Desktop.
PlanetSwift bundlePath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// String+Bundle.swift | |
// PlanetSwift | |
// | |
// Created by Brad Bambara on 1/13/15. | |
// Copyright (c) 2015 Small Planet. All rights reserved. | |
// | |
import Foundation | |
extension String { | |
public init(bundlePath:String) { | |
self.init() | |
let pathComponents = bundlePath.components(separatedBy: ":/") | |
switch pathComponents[0] { | |
case "bundle": | |
if let resourcePath = Bundle.main.resourcePath { | |
self = NSString(string: resourcePath).appendingPathComponent(pathComponents[1]) | |
} | |
case "documents": | |
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] | |
self = NSString(string: documentsPath).appendingPathComponent(pathComponents[1]) | |
case "cache": | |
let cachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] | |
self = NSString(string: cachePath).appendingPathComponent(pathComponents[1]) | |
default: | |
self = bundlePath | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment