-
Notifications
You must be signed in to change notification settings - Fork 1
LocalStorage
Local Storage provides the moethds for dealing with local files and direcotries. This includes creation, moving , saving, loading and removing of these items.
## Paths and URL Methods
Reletive path for images.
Declaration
Swift
public class func imagesReletivePath() -> String
**Return Value**
“Images/” string.
---
<br>
### dataReletivePath()
Reletive path for data.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func dataReletivePath() -> String
Return Value
“Data/” string.
User data filename.
Declaration
Swift
private class func userDataFilename() -> String
**Return Value**
“User.data” string filename.
---
<br>
### documentsURL()
URL for the documents directory.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func documentsURL() -> URL
Return Value
Documents directory URL.
URL for the caches directory.
Declaration
Swift
public class func cachesURL() -> URL
**Return Value**
Caches directory URL.
---
<br>
### sharedContainerURL(groupIdentifier:)
URL for the shared container if available.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func sharedContainerURL(groupIdentifier: String) -> URL?
Parameters
| `groupIdentifier` | The group identifier for the shared container. |
Return Value
Shared container URL, or nil if not available.
Returns the URL the correct directory passed in. Only the Document and Caches directorys are parsed. Any other value will return nil and print an error warning to the console.
Declaration
Swift
class func baseURL(directory: FileManager.SearchPathDirectory) -> URL?
**Parameters**
<table>
<tr><td> `directory` </td><td> The search path directory to use. </td></tr>
<table>
**Return Value**
The correct URL for the seatch path directory.
---
<br>
### absoluteURL(directory:reletivePath:fileName:fileExtension:)
Returns the absolute URL for a specific seatch path directory, reletive path and file name.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
class func absoluteURL(directory: FileManager.SearchPathDirectory, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> URL?
Parameters
| `directory` | The search path directory to use. |
| `reletivePath` | The reletive path to of the file or directory. |
| `fileName` | The name of the file with a default of nil if a directory is being requested. |
| `fileExtension` | The name of the file extension. |
Return Value
A URL comprised of the passed in parameters
A private class for the public class function.
Declaration
Swift
private class func absoluteURL(baseURL: URL, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> URL?
**Parameters**
<table>
<tr><td> `baseURL` </td><td> The base URL of the absolute to be created. </td></tr>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file with a default of nil if a directory is being requested. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
**Return Value**
A non-optional version of the public class function.
---
<br>
## Directory Creation Methods <br>
### createDirectory(url:)
Creates a directory at a paticular URL.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
internal class func createDirectory(url: URL)
Parameters
| `url` | The url of the directory to be created. |
## Save Methods
Saved data to the base URL, reletive path and filename.
Declaration
Swift
public class func save(data: Any, baseURL: URL, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> Bool
**Parameters**
<table>
<tr><td> `data` </td><td> The data to be saved. </td></tr>
<tr><td> `baseURL` </td><td> The search path directory to use. </td></tr>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
**Return Value**
true if the data saves correctly. false if it fails and an error will be printed regarding the nature of the nature of the error.
---
<br>
### save(toDocuments:reletivePath:fileName:fileExtension:)
Saves data to the documents directory.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func save(toDocuments data: Any, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> Bool
Parameters
| `data` | The data to be saved. |
| `reletivePath` | The reletive path to of the file or directory. |
| `fileName` | The name of the file. |
| `fileExtension` | The name of the file extension. |
Return Value
true if the data saves correctly. false if it fails and an error will be printed regarding the nature of the nature of the error.
Saves data to the caches directory.
Declaration
Swift
public class func save(toCaches data: Any, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> Bool
**Parameters**
<table>
<tr><td> `data` </td><td> The data to be saved. </td></tr>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
**Return Value**
true if the data saves correctly. false if it fails and an error will be printed regarding the nature of the nature of the error.
---
<br>
### save(userData:)
Saves user data.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func save(userData data: Any) -> Bool
Parameters
| `data` | The data to be saved. |
Return Value
true if the data saves correctly. false if it fails and an error will be printed regarding the nature of the nature of the error.
## Move Methods
Moves files from a base URL to anouther with the same reletive path and file name. This is to be mainly used to move items from documents to the caches directories and vice versa.
Declaration
Swift
private class func move(fromBaseURL: URL, toBaseURL: URL, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) throws
**Parameters**
<table>
<tr><td> `fromBaseURL` </td><td> The original search path directory. </td></tr>
<tr><td> `toBaseURL` </td><td> The new search path directory. </td></tr>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
---
<br>
### move(fromCachesToDocuments:fileName:fileExtension:)
Moves files from cache to the documents directory in relation to the reletive path and file name.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func move(fromCachesToDocuments reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) throws
Parameters
| `reletivePath` | The reletive path to of the file or directory. |
| `fileName` | The name of the file. |
| `fileExtension` | The name of the file extension. |
Moves files from documents to the caches directory in relation to the reletive path and file name.
Declaration
Swift
public class func move(fromDocumentsToCaches reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) throws
**Parameters**
<table>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
---
<br>
## Load Methods <br>
### load(baseURL:reletivePath:fileName:fileExtension:)
Loads files from a base URL to anouther with the same reletive path and file name.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func load(baseURL: URL, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> Any?
Parameters
| `baseURL` | The search path directory to use. |
| `reletivePath` | The reletive path to of the file or directory. |
| `fileName` | The name of the file. |
| `fileExtension` | The name of the file extension. |
Return Value
The object to be loaded or nil if it isn’t found.
Loads files based in the documents directory.
Declaration
Swift
public class func load(fromDocuments reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> Any?
**Parameters**
<table>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
**Return Value**
The file requested to be loaded or nil if it isn’t found.
---
<br>
### load(fromCaches:fileName:fileExtension:)
Loads files based in the caches directory.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func load(fromCaches reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> Any?
Parameters
| `reletivePath` | The reletive path to of the file or directory. |
| `fileName` | The name of the file. |
| `fileExtension` | The name of the file extension. |
Return Value
The file requested to be loaded or nil if it isn’t found.
Loads images based in the documents directory.
Declaration
Swift
public class func loadImage(fromDocuments reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> UIImage?
**Parameters**
<table>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
**Return Value**
The image requested to be loaded or nil if it isn’t found.
---
<br>
### loadImage(fromCaches:fileName:fileExtension:)
Loads images based in the caches directory.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func loadImage(fromCaches reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) -> UIImage?
Parameters
| `reletivePath` | The reletive path to of the file or directory. |
| `fileName` | The name of the file. |
| `fileExtension` | The name of the file extension. |
Return Value
The image requested to be loaded or nil if it isn’t found.
Loads the user data object.
Declaration
Swift
public class func loadUserData() -> Any?
**Return Value**
The user data object requested to be loaded or nil if it isn’t found.
---
<br>
## Delete Methods <br>
### remove(absoluteURL:)
Removes an object at an absolute path. On success this method will remove the item from the Content Manager.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
class func remove(absoluteURL: URL) throws
Parameters
| `absoluteURL` | Absolute path of the item to remove. |
Removes the file or directory from the base url in relation to the reletive path and file name. On success this method will remove the item from the Content Manager.
Declaration
Swift
private class func remove(baseURL: URL, reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) throws
**Parameters**
<table>
<tr><td> `baseURL` </td><td> The search path directory to use. </td></tr>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
---
<br>
### removeDocumentsImagesDirectory()
Removes the images directory in the documents root directory.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func removeDocumentsImagesDirectory() throws
Removes the data directory in the documents root directory.
Declaration
Swift
public class func removeDocumentsDataDirectory() throws
---
<br>
### removeCachesImagesDirectory()
Removes the images directory in the caches root directory.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func removeCachesImagesDirectory() throws
Removes the data directory in the caches root directory.
Declaration
Swift
public class func removeCachesDataDirectory() throws
---
<br>
### remove(documentsObject:fileName:fileExtension:)
Removes a file or directory in the documents root directory in relation to the reletive path and file name.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public class func remove(documentsObject reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) throws
Parameters
| `reletivePath` | The reletive path to of the file or directory. |
| `fileName` | The name of the file. |
| `fileExtension` | The name of the file extension. |
Removes a file or directory in the caches root directory in relation to the reletive path and file name.
Declaration
Swift
public class func remove(cachesObject reletivePath: String, fileName: String? = nil, fileExtension: String? = nil) throws
**Parameters**
<table>
<tr><td> `reletivePath` </td><td> The reletive path to of the file or directory. </td></tr>
<tr><td> `fileName` </td><td> The name of the file. </td></tr>
<tr><td> `fileExtension` </td><td> The name of the file extension. </td></tr>
<table>
---
<div class="footer" align="center"><sub>Built with <a href="https://github.com/Baza207/LittleHedgehogDocs" target="_blank">Little Hedgehog Docs</a> by <a href="mailto:james@pigonahill.com" target="_blank">James Barrow</a> - <a href="http://pigonahill.com" target="_blank">Pig on a Hill Productions</a>.</sub></div>