{"id":21415315,"url":"https://github.com/wibosco/convenientfilemanager","last_synced_at":"2025-07-14T04:31:40.988Z","repository":{"id":56906601,"uuid":"49365448","full_name":"wibosco/ConvenientFileManager","owner":"wibosco","description":"A suite of categories to ease using (NS)FileManager for common tasks.","archived":false,"fork":false,"pushed_at":"2019-12-12T11:20:58.000Z","size":238,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-28T18:00:06.754Z","etag":null,"topics":["cocoapods","ios","nsfilemanager","swift","unit-testing"],"latest_commit_sha":null,"homepage":"https://williamboles.com/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wibosco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-10T12:15:24.000Z","updated_at":"2022-07-20T20:50:21.000Z","dependencies_parsed_at":"2022-08-20T19:50:24.323Z","dependency_job_id":null,"html_url":"https://github.com/wibosco/ConvenientFileManager","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wibosco%2FConvenientFileManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wibosco%2FConvenientFileManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wibosco%2FConvenientFileManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wibosco%2FConvenientFileManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wibosco","download_url":"https://codeload.github.com/wibosco/ConvenientFileManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225950165,"owners_count":17550296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","ios","nsfilemanager","swift","unit-testing"],"created_at":"2024-11-22T18:46:52.833Z","updated_at":"2024-11-22T18:46:53.639Z","avatar_url":"https://github.com/wibosco.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/wibosco/ConvenientFileManager.svg)](https://travis-ci.org/wibosco/ConvenientFileManager)\n[![Version](https://img.shields.io/cocoapods/v/ConvenientFileManager.svg?style=flat)](http://cocoapods.org/pods/ConvenientFileManager)\n[![License](https://img.shields.io/cocoapods/l/ConvenientFileManager.svg?style=flat)](http://cocoapods.org/pods/ConvenientFileManager)\n[![Platform](https://img.shields.io/cocoapods/p/ConvenientFileManager.svg?style=flat)](http://cocoapods.org/pods/ConvenientFileManager)\n[![CocoaPods](https://img.shields.io/cocoapods/metrics/doc-percent/ConvenientFileManager.svg)](http://cocoapods.org/pods/ConvenientFileManager)\n\u003ca href=\"https://twitter.com/wibosco\"\u003e\u003cimg src=\"https://img.shields.io/badge/twitter-@wibosco-blue.svg?style=flat\" alt=\"Twitter: @wibosco\" /\u003e\u003c/a\u003e\n\nConvenientFileManager is a suite of categories to ease using `(NS)FileManager` for common tasks.\n\n## Installation via [CocoaPods](https://cocoapods.org/)\n\nTo integrate ConvenientFileManager into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\n\npod 'ConvenientFileManager'\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n\u003e CocoaPods 0.39.0+ is required to build ConvenientFileManager.\n\n## Usage\n\nConvenientFileManager comes with a suite of convenience methods for the `Documents` (`FileManager+Documents`) and `Cache` (`FileManager+Cache`) directories in your app's sandbox. These extensions/categories provide a streamlined interface for reading, writing and deleting data from these directories over what `(NS)FileManager` provides by removing some of the boilerplate around which directory you are using.\n\nEven if you already have the absolute path for reading, writing or deleting data you have access to the same suite of methods by using `FileManager+Persistence`.\n\n#### Writing/Saving\n\n###### Swift\n\n```swift\nfunc writeImageToDisk(image: UIImage) {\n    if let imageData = UIImagePNGRepresentation(image) {\n        switch self.media.location.integerValue {\n        case .cache:\n            FileManager.writeToCacheDirectory(data: imageData, relativePath: self.media.name)\n        case .documents:\n            FileManager.writeDataToDocumentsDirectory(data: imageData, relativePath: self.media.name)\n        }\n    }\n}\n```\n\n###### Objective-C\n\n```objc\n- (void)writeImageToDisk:(UIImage *)image\n{\n    NSData *imageData = UIImagePNGRepresentation(image);\n\n    switch (self.media.location.integerValue)\n    {\n        case CFEMediaLocationCache:\n        {\n            [NSFileManager cfm_writeData:imageData toCacheDirectoryWithRelativePath:self.media.name];\n\n            break;\n        }\n        case CFEMediaLocationDocuments:\n        {\n            [NSFileManager cfm_writeData:imageData toDocumentsDirectoryWithRelativePath:self.media.name];\n\n            break;\n        }\n    }\n}\n```\n\n#### Retrieving\n\n###### Swift\n\n```swift\nfunc retrieveImageFromMedia(media: CFEMedia) -\u003e UIImage? {\n    var retrievedData: NSData?\n\n    switch media.location.integerValue {\n    case .cache:\n        retrievedData = FileManager.retrieveDataFromCacheDirectory(relativePath: media.name)\n    case .documents:\n        retrievedData = FileManager.retrieveDataFromDocumentsDirectory(relativePath: media.name)\n    }\n\n    guard let unwrappedRetrievedData = retrievedData else {\n        return nil\n    }\n\n    return UIImage.init(data: unwrappedRetrievedData)\n}\n```\n\n###### Objective-C\n\n```objc\n- (UIImage *)retrieveImageFromMedia:(CFEMedia *)media\n{\n    NSData *imageData = nil;\n\n    switch (media.location.integerValue)\n    {\n        case CFEMediaLocationCache:\n        {\n            imageData = [NSFileManager cfm_retrieveDataFromCacheDirectoryWithRelativePath:media.name];\n\n            break;\n        }\n        case CFEMediaLocationDocuments:\n        {\n            imageData = [NSFileManager cfm_retrieveDataFromDocumentsDirectoryWithRelativePath:media.name];\n\n            break;\n        }\n    }\n\n    return [[UIImage alloc] initWithData:imageData];\n}\n```\n\n#### Deleting\n\n###### Swift\n\n```swift\nfunc trashButtonPressed(sender: UIBarButtonItem) {\n    switch self.media.location.integerValue {\n    case .cache:\n        FileManager.deleteDataFromCacheDirectory(relativePath: self.media.name)\n    case .documents:\n        FileManager.deleteDataFromDocumentsDirectory(relativePath: self.media.name)\n    }\n}\n```\n\n###### Objective-C\n\n```objc\n- (void)trashButtonPressed:(UIBarButtonItem *)sender\n{\n    switch (self.media.location.integerValue)\n    {\n        case CFEMediaLocationCache:\n        {\n            [NSFileManager cfm_deleteDataFromCacheDirectoryWithRelativePath:self.media.name];\n\n            break;\n        }\n        case CFEMediaLocationDocuments:\n        {\n            [NSFileManager cfm_deleteDataFromDocumentDirectoryWithRelativePath:self.media.name];\n\n            break;\n        }\n    }\n}\n```\n\n#### Exists\n\n**Synchronously**\n\n###### Swift\n\n```swift\nfunc mediaAssetHasBeenDownloaded(media: CFEMedia) -\u003e Bool {\n    var mediaAssetHasBeenDownloaded = false\n\n    switch self.media.location.integerValue {\n    case .cache:\n        mediaAssetHasBeenDownloaded = FileManager.fileExistsInCacheDirectory(relativePath: self.media.name)\n    case .documents:\n        mediaAssetHasBeenDownloaded = FileManager.fileExistsInDocumentsDirectory(relativePath: self.media.name)\n    }\n\n    return mediaAssetHasBeenDownloaded\n}\n```\n\n###### Objective-C\n\n```objc\n- (BOOL)mediaAssetHasBeenDownloaded:(CFEMedia *)media\n{\n    BOOL mediaAssetHasBeenDownloaded = NO;\n\n    switch (self.media.location.integerValue)\n    {\n        case CFEMediaLocationCache:\n        {\n            mediaAssetHasBeenDownloaded = [NSFileManager cfm_fileExistsInCacheDirectoryWithRelativePath:self.media.name];\n\n            break;\n        }\n        case CFEMediaLocationDocuments:\n        {\n            mediaAssetHasBeenDownloaded = [NSFileManager cfm_fileExistsInCacheDirectoryWithRelativePath:self.media.name];\n\n            break;\n        }\n    }\n\n    return mediaAssetHasBeenDownloaded;\n}\n```\n\n**Asynchronously**\n\n###### Swift\n\n```swift\nFileManager.fileExistsAtPath(absolutePath: self.media.absoluteLocalPath) { (fileExists) in\n    if (!fileExists) {\n        //Yay!\n    } else {\n        //Boo!\n    }\n}\n```\n\n###### Objective-C\n\n```objc\n[NSFileManager cfm_fileExistsAtAbsolutePath:self.media.absoluteLocalPath\n                                 completion:^(BOOL fileExists)\n {\n     if (!fileExists)\n     {   \n        //Yay!\n     }\n     else\n     {\n        //Boo!\n     }\n }];\n```\n\n\n\u003e ConvenientFileManager comes with an [example project](https://github.com/wibosco/ConvenientFileManager/tree/master/Examples/Swift%20Example) to provide more details than listed above.\n\n\u003e ConvenientFileManager uses [modules](http://useyourloaf.com/blog/modules-and-precompiled-headers.html) for importing/using frameworks - you will need to enable this in your project.\n\n## Found an issue?\n\nPlease open a [new Issue here](https://github.com/wibosco/ConvenientFileManager/issues/new) if you run into a problem specific to ConvenientFileManager, have a feature request, or want to share a comment. Note that general NSFileManager questions should be asked on [Stack Overflow](http://stackoverflow.com).\n\nPull requests are encouraged and greatly appreciated! Please try to maintain consistency with the existing code style. If you're considering taking on significant changes or additions to the project, please communicate in advance by opening a new Issue. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwibosco%2Fconvenientfilemanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwibosco%2Fconvenientfilemanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwibosco%2Fconvenientfilemanager/lists"}