├── .DS_Store ├── .github ├── .DS_Store └── workflows │ └── test.yml ├── Resources └── Icon.png ├── .swiftpm └── xcode │ └── package.xcworkspace │ └── contents.xcworkspacedata ├── Cacher.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings ├── xcshareddata │ └── xcschemes │ │ └── Cacher.xcscheme └── project.pbxproj ├── Sources └── Cacher │ ├── Cacher.h │ ├── Info.plist │ └── Cacher.swift ├── Package.swift ├── Tests └── CacherTests │ ├── Info.plist │ └── CacherTests.swift ├── LICENSE ├── CacherDemo ├── ViewController.swift ├── Info.plist ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json └── AppDelegate.swift ├── .gitignore └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raulriera/Cacher/HEAD/.DS_Store -------------------------------------------------------------------------------- /.github/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raulriera/Cacher/HEAD/.github/.DS_Store -------------------------------------------------------------------------------- /Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raulriera/Cacher/HEAD/Resources/Icon.png -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Cacher.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Cacher.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Cacher.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildSystemType 6 | Latest 7 | 8 | 9 | -------------------------------------------------------------------------------- /Sources/Cacher/Cacher.h: -------------------------------------------------------------------------------- 1 | // 2 | // Cacher.h 3 | // Cacher 4 | // 5 | // Created by Raul Riera on 2017-07-08. 6 | // Copyright © 2017 Raul Riera. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | //! Project version number for Cacher. 12 | FOUNDATION_EXPORT double CacherVersionNumber; 13 | 14 | //! Project version string for Cacher. 15 | FOUNDATION_EXPORT const unsigned char CacherVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | - push 5 | 6 | jobs: 7 | build: 8 | 9 | runs-on: macOS-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v1 13 | - name: Xcode select 14 | run: | 15 | sudo xcode-select -s /Applications/Xcode_11.app/Contents/Developer 16 | - name: Generating project 17 | run: swift package generate-xcodeproj 18 | - name: Testing 19 | run: | 20 | xcodebuild clean test -project Cacher.xcodeproj -scheme Cacher-Package -destination "platform=iOS Simulator,OS=13.0,name=iPhone 8" 21 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "Cacher", 8 | platforms: [ 9 | .iOS(.v9) 10 | ], 11 | products: [ 12 | .library( 13 | name: "Cacher", 14 | targets: [ 15 | "Cacher" 16 | ]), 17 | ], 18 | dependencies: [], 19 | targets: [ 20 | .target( 21 | name: "Cacher", 22 | dependencies: []), 23 | .testTarget( 24 | name: "CacherTests", 25 | dependencies: [ 26 | "Cacher" 27 | ]), 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /Tests/CacherTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Sources/Cacher/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Raul Riera 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CacherDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CacherDemo 4 | // 5 | // Created by Raul Riera on 2017-07-08. 6 | // Copyright © 2017 Raul Riera. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Cacher 11 | 12 | class ViewController: UIViewController { 13 | @IBOutlet weak var textField: UITextField! 14 | 15 | // Create a cacher and use the temporary directory 16 | let cacher: Cacher = Cacher(destination: .temporary) 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | // Do any additional setup after loading the view, typically from a nib. 21 | if let cachedText: CachableText = cacher.load(fileName: "text") { 22 | // Replace the current text with the cached one 23 | textField.text = cachedText.value 24 | } 25 | } 26 | 27 | @IBAction func didPressCache(_ sender: UIButton) { 28 | let cachableText = CachableText(value: textField.text ?? "") 29 | cacher.persist(item: cachableText) { url, error in 30 | if let error = error { 31 | print("Text failed to persist: \(error)") 32 | } else { 33 | print("Text persisted in \(String(describing: url))") 34 | } 35 | } 36 | } 37 | } 38 | 39 | // Use Codable for an implicient implementation of `transform` 40 | fileprivate struct CachableText: Cachable, Codable { 41 | let fileName: String = "text" 42 | let value: String 43 | } 44 | -------------------------------------------------------------------------------- /Tests/CacherTests/CacherTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CacherTests.swift 3 | // CacherTests 4 | // 5 | // Created by Raul Riera on 2017-07-08. 6 | // Copyright © 2017 Raul Riera. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Cacher 11 | 12 | class CacherTests: XCTestCase { 13 | func testPersistCachableItemAtTemporaryFolder() { 14 | let expectation = self.expectation(description: "Wrote file in folder") 15 | 16 | Cacher(destination: .temporary).persist(item: CachableText(text: "Raul Riera")) { url, _ in 17 | #if os(OSX) 18 | let tempFolder = "T" 19 | #else 20 | let tempFolder = "tmp" 21 | #endif 22 | 23 | if url!.absoluteString.contains("/\(tempFolder)/testFile.txt") { 24 | expectation.fulfill() 25 | } 26 | } 27 | 28 | waitForExpectations(timeout: 1, handler: nil) 29 | } 30 | 31 | func testPersistCachableItemAtCustomFolder() { 32 | let expectation = self.expectation(description: "Wrote file in folder") 33 | 34 | Cacher(destination: .atFolder("/test-folder")).persist(item: CachableText(text: "Raul Riera")) { url, _ in 35 | if url!.absoluteString.contains("/test-folder/testFile.txt") { 36 | expectation.fulfill() 37 | } 38 | } 39 | 40 | waitForExpectations(timeout: 1, handler: nil) 41 | } 42 | } 43 | 44 | private class CachableText: Cachable { 45 | let text: String 46 | var fileName: String { 47 | return "testFile.txt" 48 | } 49 | 50 | init(text: String) { 51 | self.text = text 52 | } 53 | 54 | func transform() -> Data { 55 | return text.data(using: .utf8)! 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CacherDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | Packages/ 39 | Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | -------------------------------------------------------------------------------- /CacherDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CacherDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /CacherDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CacherDemo 4 | // 5 | // Created by Raul Riera on 2017-07-08. 6 | // Copyright © 2017 Raul Riera. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/raulriera/Cacher.svg?branch=master)](https://travis-ci.org/raulriera/Cacher) 2 | 3 | 4 | 5 | For a detail information about using "Cacher", checkout the article ["Caching anything in iOS"](https://medium.com/ios-os-x-development/caching-anything-in-ios-102176e46eba). 6 | 7 | ## Installation 8 | 9 | ### Manual 10 | 11 | Drag and drop the `Cacher/` folder into your project. 12 | 13 | ### Carthage 14 | 15 | Add the following to your Cartfile: 16 | 17 | ```ruby 18 | github "raulriera/Cacher" 19 | ``` 20 | 21 | ### Swift Package Manager 22 | 23 | Add this repo to your dependencies. 24 | 25 | ## How to use them 26 | 27 | For a quick TL;DR check out the sample project at `CacherDemo`. It will guide you with the simplest caching possible, persisting string values. 28 | 29 | If you like to get your hands dirty, continue reading as we are going to go into detail about how this works. 30 | 31 | ``` swift 32 | public protocol Cachable { 33 | var fileName: String { get } 34 | func transform() -> Data 35 | } 36 | ``` 37 | 38 | It all comes down to this simple protocol, that has only two requirements `fileName` which represents the unique name to store in the filesystem, and `transform` which is the `Data` representation of what you wish to import. Using the magic of Swift 4 `Codable`, we can skip the `transform` implementation and use the implicit one declared [right here](/Cacher/Cacher.swift#L110). 39 | 40 | After we implement conform to `Cachable` and `Codable`, anything can be stored in the filesystem using the `persist:item:completion` method. 41 | 42 | But, let's see a more complex example 43 | 44 | ```swift 45 | struct CachableMovies: Cachable, Codable { 46 | let store: String 47 | let movies: [Movie] 48 | 49 | var fileName: String { 50 | return "movies-\(store)" 51 | } 52 | 53 | init(store: String, movies: [Movie]) { 54 | self.store = store 55 | self.movies = movies 56 | } 57 | } 58 | 59 | struct Movie: Codable { 60 | enum CodingKeys : String, CodingKey { 61 | case title = "movie_title" 62 | case description = "movie_description" 63 | case url = "movie_url" 64 | } 65 | 66 | let title: String 67 | let description: String 68 | let url: URL 69 | } 70 | ``` 71 | 72 | The previous code is all we need to store a collection of movies into the filesystem. 🎉 Now we can simply use the `persist` method like this. 73 | 74 | ```swift 75 | Cacher(destination: .temporary).persist(item: CachableMovies(store: "USA", movies: myArrayOfMovies)) { url, error in 76 | // Completion handler when the process finishes 77 | } 78 | ``` 79 | 80 | ## Created by 81 | Raul Riera, [@raulriera](http://twitter.com/raulriera) 82 | -------------------------------------------------------------------------------- /Cacher.xcodeproj/xcshareddata/xcschemes/Cacher.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Sources/Cacher/Cacher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Cacher.swift 3 | // Cacher 4 | // 5 | // Created by Raul Riera on 2017-07-08. 6 | // Copyright © 2017 Raul Riera. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /// `Cacher` is a super simple cross platform solution to persist `Cachable` types into the filesystem. 12 | final public class Cacher { 13 | /// The path in the filesystem that will hold all the persisted items 14 | let destination: URL 15 | private let queue = OperationQueue() 16 | 17 | /// A type for the type of persistance options. 18 | /// 19 | /// - temporary: stores `Cachable` types into the temporary folder of the OS. 20 | /// - atFolder: stores `Cachable` types into a specific folder in the OS. 21 | public enum CacheDestination { 22 | /// Stores items in `NSTemporaryDirectory` 23 | case temporary 24 | /// Stores items at a specific location 25 | case atFolder(String) 26 | } 27 | 28 | // MARK: Initialization 29 | 30 | /// Initializes a newly created `Cacher` instance using the specified storage destination. 31 | /// *Note* If using `.atFolder(String)` make sure the destination is valid. 32 | /// 33 | /// - Parameter destination: path to the location where `Cacher` will persist its `Cachable` items. 34 | public init(destination: CacheDestination) { 35 | switch destination { 36 | case .temporary: 37 | self.destination = URL(fileURLWithPath: NSTemporaryDirectory()) 38 | case .atFolder(let folder): 39 | let documentFolder = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] 40 | self.destination = URL(fileURLWithPath: documentFolder).appendingPathComponent(folder, isDirectory: true) 41 | } 42 | 43 | try? FileManager.default.createDirectory(at: self.destination, withIntermediateDirectories: true, attributes: nil) 44 | } 45 | 46 | // MARK 47 | 48 | /// Store a `Cachable` object in the directory selected by this `Cacher` instance. 49 | /// 50 | /// - Parameters: 51 | /// - item: `Cachable` object to persist in the filesystem 52 | /// - completion: callback invoked when the persistance finishes, it will either contain the `URL` of the persisted item, or the `Error` raised while trying to. 53 | public func persist(item: Cachable, completion: @escaping (_ url: URL?, _ error: Error?) -> Void) { 54 | var url: URL? 55 | var error: Error? 56 | 57 | // Create an operation to process the request. 58 | let operation = BlockOperation { 59 | do { 60 | url = try self.persist(data: item.transform(), at: self.destination.appendingPathComponent(item.fileName, isDirectory: false)) 61 | } catch let persistError { 62 | error = persistError 63 | } 64 | } 65 | 66 | // Set the operation's completion block to call the request's completion handler. 67 | operation.completionBlock = { 68 | completion(url, error) 69 | } 70 | 71 | // Add the operation to the queue to start the work. 72 | queue.addOperation(operation) 73 | } 74 | 75 | /// Load cached data from the directory 76 | /// 77 | /// - Parameter fileName: of the cached data stored in the file system 78 | /// - Returns: the decoded cached data (if any) 79 | public func load(fileName: String) -> T? { 80 | guard 81 | let data = try? Data(contentsOf: destination.appendingPathComponent(fileName, isDirectory: false)), 82 | let decoded = try? JSONDecoder().decode(T.self, from: data) 83 | else { return nil } 84 | return decoded 85 | } 86 | 87 | /// Remove cached data from the directory giving an File Name 88 | /// 89 | /// - Parameter fileName: of the cached data stored in the file system 90 | public func removeCache(fileName: String) { 91 | let fileManager = FileManager.default 92 | 93 | do { 94 | let path = destination.appendingPathComponent(fileName) 95 | try fileManager.removeItem(at: path) 96 | } catch let error { 97 | fatalError("Unable to remove object: \(error)") 98 | } 99 | } 100 | 101 | /// Remove all cached data from the directory 102 | public func removeCache() { 103 | let fileManager = FileManager.default 104 | 105 | do { 106 | try fileManager.removeItem(at: destination) 107 | } catch let error { 108 | fatalError("Unable to remove objects: \(error)") 109 | } 110 | } 111 | 112 | // MARK: Private 113 | 114 | private func persist(data: Data, at url: URL) throws -> URL { 115 | do { 116 | try data.write(to: url, options: [.atomicWrite]) 117 | return url 118 | } catch let error { 119 | throw error 120 | } 121 | } 122 | } 123 | 124 | /// A type that can persist itself into the filesystem. 125 | public protocol Cachable { 126 | /// The item's name in the filesystem. 127 | var fileName: String { get } 128 | 129 | /// Returns a `Data` encoded representation of the item. 130 | /// 131 | /// - Returns: `Data` representation of the item. 132 | func transform() -> Data 133 | } 134 | 135 | extension Cachable where Self: Codable { 136 | public func transform() -> Data { 137 | do { 138 | let encoded = try JSONEncoder().encode(self) 139 | return encoded 140 | } catch let error { 141 | fatalError("Unable to encode object: \(error)") 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /CacherDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 37 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Cacher.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4C65D7B1238C148D008E21CD /* Cacher.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C710F1F238B171600EB455F /* Cacher.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 4C710F21238B171600EB455F /* Cacher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C710F1E238B171600EB455F /* Cacher.swift */; }; 12 | 4C710F28238B172A00EB455F /* CacherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C710F26238B172A00EB455F /* CacherTests.swift */; }; 13 | 4CB7615B1F116F9C00E6F9BE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB7615A1F116F9C00E6F9BE /* AppDelegate.swift */; }; 14 | 4CB7615D1F116F9C00E6F9BE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB7615C1F116F9C00E6F9BE /* ViewController.swift */; }; 15 | 4CB761601F116F9C00E6F9BE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4CB7615E1F116F9C00E6F9BE /* Main.storyboard */; }; 16 | 4CB761621F116F9C00E6F9BE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4CB761611F116F9C00E6F9BE /* Assets.xcassets */; }; 17 | 4CB761651F116F9C00E6F9BE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4CB761631F116F9C00E6F9BE /* LaunchScreen.storyboard */; }; 18 | 4CCF5E5A1F5DEF7300CDC01C /* Cacher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CE8823A1F116D8400A2F3D8 /* Cacher.framework */; }; 19 | 4CCF5E5B1F5DEF7300CDC01C /* Cacher.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4CE8823A1F116D8400A2F3D8 /* Cacher.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 20 | 4CE882441F116D8400A2F3D8 /* Cacher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CE8823A1F116D8400A2F3D8 /* Cacher.framework */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 4C11C6C61F8537A500EE0E35 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 4CE882311F116D8400A2F3D8 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 4CE882391F116D8400A2F3D8; 29 | remoteInfo = Cacher; 30 | }; 31 | 4C710F2C238C138C00EB455F /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 4CE882311F116D8400A2F3D8 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 4CB761571F116F9B00E6F9BE; 36 | remoteInfo = CacherDemo; 37 | }; 38 | 4CE882451F116D8400A2F3D8 /* PBXContainerItemProxy */ = { 39 | isa = PBXContainerItemProxy; 40 | containerPortal = 4CE882311F116D8400A2F3D8 /* Project object */; 41 | proxyType = 1; 42 | remoteGlobalIDString = 4CE882391F116D8400A2F3D8; 43 | remoteInfo = Cacher; 44 | }; 45 | /* End PBXContainerItemProxy section */ 46 | 47 | /* Begin PBXCopyFilesBuildPhase section */ 48 | 4CCF5E5E1F5DEF7300CDC01C /* Embed Frameworks */ = { 49 | isa = PBXCopyFilesBuildPhase; 50 | buildActionMask = 2147483647; 51 | dstPath = ""; 52 | dstSubfolderSpec = 10; 53 | files = ( 54 | 4CCF5E5B1F5DEF7300CDC01C /* Cacher.framework in Embed Frameworks */, 55 | ); 56 | name = "Embed Frameworks"; 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXCopyFilesBuildPhase section */ 60 | 61 | /* Begin PBXFileReference section */ 62 | 4C710F1E238B171600EB455F /* Cacher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cacher.swift; sourceTree = ""; }; 63 | 4C710F1F238B171600EB455F /* Cacher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cacher.h; sourceTree = ""; }; 64 | 4C710F20238B171600EB455F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65 | 4C710F26238B172A00EB455F /* CacherTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CacherTests.swift; sourceTree = ""; }; 66 | 4C710F27238B172A00EB455F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 67 | 4CB761581F116F9B00E6F9BE /* CacherDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CacherDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 68 | 4CB7615A1F116F9C00E6F9BE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 69 | 4CB7615C1F116F9C00E6F9BE /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 70 | 4CB7615F1F116F9C00E6F9BE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 71 | 4CB761611F116F9C00E6F9BE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 72 | 4CB761641F116F9C00E6F9BE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 73 | 4CB761661F116F9C00E6F9BE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 74 | 4CE8823A1F116D8400A2F3D8 /* Cacher.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Cacher.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 75 | 4CE882431F116D8400A2F3D8 /* CacherTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CacherTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 76 | /* End PBXFileReference section */ 77 | 78 | /* Begin PBXFrameworksBuildPhase section */ 79 | 4CB761551F116F9B00E6F9BE /* Frameworks */ = { 80 | isa = PBXFrameworksBuildPhase; 81 | buildActionMask = 2147483647; 82 | files = ( 83 | 4CCF5E5A1F5DEF7300CDC01C /* Cacher.framework in Frameworks */, 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | 4CE882361F116D8400A2F3D8 /* Frameworks */ = { 88 | isa = PBXFrameworksBuildPhase; 89 | buildActionMask = 2147483647; 90 | files = ( 91 | ); 92 | runOnlyForDeploymentPostprocessing = 0; 93 | }; 94 | 4CE882401F116D8400A2F3D8 /* Frameworks */ = { 95 | isa = PBXFrameworksBuildPhase; 96 | buildActionMask = 2147483647; 97 | files = ( 98 | 4CE882441F116D8400A2F3D8 /* Cacher.framework in Frameworks */, 99 | ); 100 | runOnlyForDeploymentPostprocessing = 0; 101 | }; 102 | /* End PBXFrameworksBuildPhase section */ 103 | 104 | /* Begin PBXGroup section */ 105 | 4C710F1A238B171600EB455F /* Sources */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 4CF38EAB238DE86A00CFA350 /* Cacher */, 109 | ); 110 | path = Sources; 111 | sourceTree = ""; 112 | }; 113 | 4C710F24238B172A00EB455F /* Tests */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 4CF38EAC238DE87800CFA350 /* CacherTests */, 117 | ); 118 | path = Tests; 119 | sourceTree = ""; 120 | }; 121 | 4CB761591F116F9C00E6F9BE /* CacherDemo */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 4CB7615A1F116F9C00E6F9BE /* AppDelegate.swift */, 125 | 4CB7615C1F116F9C00E6F9BE /* ViewController.swift */, 126 | 4CB7615E1F116F9C00E6F9BE /* Main.storyboard */, 127 | 4CB761611F116F9C00E6F9BE /* Assets.xcassets */, 128 | 4CB761631F116F9C00E6F9BE /* LaunchScreen.storyboard */, 129 | 4CB761661F116F9C00E6F9BE /* Info.plist */, 130 | ); 131 | path = CacherDemo; 132 | sourceTree = ""; 133 | }; 134 | 4CDE502B1FEEF97F005E814F /* Frameworks */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | ); 138 | name = Frameworks; 139 | sourceTree = ""; 140 | }; 141 | 4CE882301F116D8400A2F3D8 = { 142 | isa = PBXGroup; 143 | children = ( 144 | 4CB761591F116F9C00E6F9BE /* CacherDemo */, 145 | 4CDE502B1FEEF97F005E814F /* Frameworks */, 146 | 4CE8823B1F116D8400A2F3D8 /* Products */, 147 | 4C710F1A238B171600EB455F /* Sources */, 148 | 4C710F24238B172A00EB455F /* Tests */, 149 | ); 150 | sourceTree = ""; 151 | }; 152 | 4CE8823B1F116D8400A2F3D8 /* Products */ = { 153 | isa = PBXGroup; 154 | children = ( 155 | 4CE8823A1F116D8400A2F3D8 /* Cacher.framework */, 156 | 4CE882431F116D8400A2F3D8 /* CacherTests.xctest */, 157 | 4CB761581F116F9B00E6F9BE /* CacherDemo.app */, 158 | ); 159 | name = Products; 160 | sourceTree = ""; 161 | }; 162 | 4CF38EAB238DE86A00CFA350 /* Cacher */ = { 163 | isa = PBXGroup; 164 | children = ( 165 | 4C710F1E238B171600EB455F /* Cacher.swift */, 166 | 4C710F1F238B171600EB455F /* Cacher.h */, 167 | 4C710F20238B171600EB455F /* Info.plist */, 168 | ); 169 | path = Cacher; 170 | sourceTree = ""; 171 | }; 172 | 4CF38EAC238DE87800CFA350 /* CacherTests */ = { 173 | isa = PBXGroup; 174 | children = ( 175 | 4C710F26238B172A00EB455F /* CacherTests.swift */, 176 | 4C710F27238B172A00EB455F /* Info.plist */, 177 | ); 178 | path = CacherTests; 179 | sourceTree = ""; 180 | }; 181 | /* End PBXGroup section */ 182 | 183 | /* Begin PBXHeadersBuildPhase section */ 184 | 4CE882371F116D8400A2F3D8 /* Headers */ = { 185 | isa = PBXHeadersBuildPhase; 186 | buildActionMask = 2147483647; 187 | files = ( 188 | 4C65D7B1238C148D008E21CD /* Cacher.h in Headers */, 189 | ); 190 | runOnlyForDeploymentPostprocessing = 0; 191 | }; 192 | /* End PBXHeadersBuildPhase section */ 193 | 194 | /* Begin PBXNativeTarget section */ 195 | 4CB761571F116F9B00E6F9BE /* CacherDemo */ = { 196 | isa = PBXNativeTarget; 197 | buildConfigurationList = 4CB761671F116F9C00E6F9BE /* Build configuration list for PBXNativeTarget "CacherDemo" */; 198 | buildPhases = ( 199 | 4CB761541F116F9B00E6F9BE /* Sources */, 200 | 4CB761551F116F9B00E6F9BE /* Frameworks */, 201 | 4CB761561F116F9B00E6F9BE /* Resources */, 202 | 4CCF5E5E1F5DEF7300CDC01C /* Embed Frameworks */, 203 | ); 204 | buildRules = ( 205 | ); 206 | dependencies = ( 207 | 4CCF5E5D1F5DEF7300CDC01C /* PBXTargetDependency */, 208 | ); 209 | name = CacherDemo; 210 | productName = CacherDemo; 211 | productReference = 4CB761581F116F9B00E6F9BE /* CacherDemo.app */; 212 | productType = "com.apple.product-type.application"; 213 | }; 214 | 4CE882391F116D8400A2F3D8 /* Cacher */ = { 215 | isa = PBXNativeTarget; 216 | buildConfigurationList = 4CE8824E1F116D8400A2F3D8 /* Build configuration list for PBXNativeTarget "Cacher" */; 217 | buildPhases = ( 218 | 4CE882351F116D8400A2F3D8 /* Sources */, 219 | 4CE882361F116D8400A2F3D8 /* Frameworks */, 220 | 4CE882371F116D8400A2F3D8 /* Headers */, 221 | 4CE882381F116D8400A2F3D8 /* Resources */, 222 | ); 223 | buildRules = ( 224 | ); 225 | dependencies = ( 226 | ); 227 | name = Cacher; 228 | productName = Cacher; 229 | productReference = 4CE8823A1F116D8400A2F3D8 /* Cacher.framework */; 230 | productType = "com.apple.product-type.framework"; 231 | }; 232 | 4CE882421F116D8400A2F3D8 /* CacherTests */ = { 233 | isa = PBXNativeTarget; 234 | buildConfigurationList = 4CE882511F116D8400A2F3D8 /* Build configuration list for PBXNativeTarget "CacherTests" */; 235 | buildPhases = ( 236 | 4CE8823F1F116D8400A2F3D8 /* Sources */, 237 | 4CE882401F116D8400A2F3D8 /* Frameworks */, 238 | 4CE882411F116D8400A2F3D8 /* Resources */, 239 | ); 240 | buildRules = ( 241 | ); 242 | dependencies = ( 243 | 4CE882461F116D8400A2F3D8 /* PBXTargetDependency */, 244 | 4C710F2D238C138C00EB455F /* PBXTargetDependency */, 245 | ); 246 | name = CacherTests; 247 | productName = CacherTests; 248 | productReference = 4CE882431F116D8400A2F3D8 /* CacherTests.xctest */; 249 | productType = "com.apple.product-type.bundle.unit-test"; 250 | }; 251 | /* End PBXNativeTarget section */ 252 | 253 | /* Begin PBXProject section */ 254 | 4CE882311F116D8400A2F3D8 /* Project object */ = { 255 | isa = PBXProject; 256 | attributes = { 257 | LastSwiftUpdateCheck = 0900; 258 | LastUpgradeCheck = 0930; 259 | ORGANIZATIONNAME = "Raul Riera"; 260 | TargetAttributes = { 261 | 4CB761571F116F9B00E6F9BE = { 262 | CreatedOnToolsVersion = 9.0; 263 | LastSwiftMigration = 1120; 264 | }; 265 | 4CE882391F116D8400A2F3D8 = { 266 | CreatedOnToolsVersion = 9.0; 267 | LastSwiftMigration = 1120; 268 | ProvisioningStyle = Manual; 269 | }; 270 | 4CE882421F116D8400A2F3D8 = { 271 | CreatedOnToolsVersion = 9.0; 272 | ProvisioningStyle = Automatic; 273 | }; 274 | }; 275 | }; 276 | buildConfigurationList = 4CE882341F116D8400A2F3D8 /* Build configuration list for PBXProject "Cacher" */; 277 | compatibilityVersion = "Xcode 8.0"; 278 | developmentRegion = en; 279 | hasScannedForEncodings = 0; 280 | knownRegions = ( 281 | en, 282 | Base, 283 | ); 284 | mainGroup = 4CE882301F116D8400A2F3D8; 285 | productRefGroup = 4CE8823B1F116D8400A2F3D8 /* Products */; 286 | projectDirPath = ""; 287 | projectRoot = ""; 288 | targets = ( 289 | 4CE882391F116D8400A2F3D8 /* Cacher */, 290 | 4CE882421F116D8400A2F3D8 /* CacherTests */, 291 | 4CB761571F116F9B00E6F9BE /* CacherDemo */, 292 | ); 293 | }; 294 | /* End PBXProject section */ 295 | 296 | /* Begin PBXResourcesBuildPhase section */ 297 | 4CB761561F116F9B00E6F9BE /* Resources */ = { 298 | isa = PBXResourcesBuildPhase; 299 | buildActionMask = 2147483647; 300 | files = ( 301 | 4CB761651F116F9C00E6F9BE /* LaunchScreen.storyboard in Resources */, 302 | 4CB761621F116F9C00E6F9BE /* Assets.xcassets in Resources */, 303 | 4CB761601F116F9C00E6F9BE /* Main.storyboard in Resources */, 304 | ); 305 | runOnlyForDeploymentPostprocessing = 0; 306 | }; 307 | 4CE882381F116D8400A2F3D8 /* Resources */ = { 308 | isa = PBXResourcesBuildPhase; 309 | buildActionMask = 2147483647; 310 | files = ( 311 | ); 312 | runOnlyForDeploymentPostprocessing = 0; 313 | }; 314 | 4CE882411F116D8400A2F3D8 /* Resources */ = { 315 | isa = PBXResourcesBuildPhase; 316 | buildActionMask = 2147483647; 317 | files = ( 318 | ); 319 | runOnlyForDeploymentPostprocessing = 0; 320 | }; 321 | /* End PBXResourcesBuildPhase section */ 322 | 323 | /* Begin PBXSourcesBuildPhase section */ 324 | 4CB761541F116F9B00E6F9BE /* Sources */ = { 325 | isa = PBXSourcesBuildPhase; 326 | buildActionMask = 2147483647; 327 | files = ( 328 | 4CB7615D1F116F9C00E6F9BE /* ViewController.swift in Sources */, 329 | 4CB7615B1F116F9C00E6F9BE /* AppDelegate.swift in Sources */, 330 | ); 331 | runOnlyForDeploymentPostprocessing = 0; 332 | }; 333 | 4CE882351F116D8400A2F3D8 /* Sources */ = { 334 | isa = PBXSourcesBuildPhase; 335 | buildActionMask = 2147483647; 336 | files = ( 337 | 4C710F21238B171600EB455F /* Cacher.swift in Sources */, 338 | ); 339 | runOnlyForDeploymentPostprocessing = 0; 340 | }; 341 | 4CE8823F1F116D8400A2F3D8 /* Sources */ = { 342 | isa = PBXSourcesBuildPhase; 343 | buildActionMask = 2147483647; 344 | files = ( 345 | 4C710F28238B172A00EB455F /* CacherTests.swift in Sources */, 346 | ); 347 | runOnlyForDeploymentPostprocessing = 0; 348 | }; 349 | /* End PBXSourcesBuildPhase section */ 350 | 351 | /* Begin PBXTargetDependency section */ 352 | 4C710F2D238C138C00EB455F /* PBXTargetDependency */ = { 353 | isa = PBXTargetDependency; 354 | target = 4CB761571F116F9B00E6F9BE /* CacherDemo */; 355 | targetProxy = 4C710F2C238C138C00EB455F /* PBXContainerItemProxy */; 356 | }; 357 | 4CCF5E5D1F5DEF7300CDC01C /* PBXTargetDependency */ = { 358 | isa = PBXTargetDependency; 359 | target = 4CE882391F116D8400A2F3D8 /* Cacher */; 360 | targetProxy = 4C11C6C61F8537A500EE0E35 /* PBXContainerItemProxy */; 361 | }; 362 | 4CE882461F116D8400A2F3D8 /* PBXTargetDependency */ = { 363 | isa = PBXTargetDependency; 364 | target = 4CE882391F116D8400A2F3D8 /* Cacher */; 365 | targetProxy = 4CE882451F116D8400A2F3D8 /* PBXContainerItemProxy */; 366 | }; 367 | /* End PBXTargetDependency section */ 368 | 369 | /* Begin PBXVariantGroup section */ 370 | 4CB7615E1F116F9C00E6F9BE /* Main.storyboard */ = { 371 | isa = PBXVariantGroup; 372 | children = ( 373 | 4CB7615F1F116F9C00E6F9BE /* Base */, 374 | ); 375 | name = Main.storyboard; 376 | sourceTree = ""; 377 | }; 378 | 4CB761631F116F9C00E6F9BE /* LaunchScreen.storyboard */ = { 379 | isa = PBXVariantGroup; 380 | children = ( 381 | 4CB761641F116F9C00E6F9BE /* Base */, 382 | ); 383 | name = LaunchScreen.storyboard; 384 | sourceTree = ""; 385 | }; 386 | /* End PBXVariantGroup section */ 387 | 388 | /* Begin XCBuildConfiguration section */ 389 | 4CB761681F116F9C00E6F9BE /* Debug */ = { 390 | isa = XCBuildConfiguration; 391 | buildSettings = { 392 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 393 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 394 | DEVELOPMENT_TEAM = R64MTWS872; 395 | INFOPLIST_FILE = CacherDemo/Info.plist; 396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 397 | PRODUCT_BUNDLE_IDENTIFIER = com.raulriera.CacherDemo; 398 | PRODUCT_NAME = "$(TARGET_NAME)"; 399 | SWIFT_VERSION = 5.0; 400 | TARGETED_DEVICE_FAMILY = "1,2"; 401 | }; 402 | name = Debug; 403 | }; 404 | 4CB761691F116F9C00E6F9BE /* Release */ = { 405 | isa = XCBuildConfiguration; 406 | buildSettings = { 407 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 408 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 409 | DEVELOPMENT_TEAM = R64MTWS872; 410 | INFOPLIST_FILE = CacherDemo/Info.plist; 411 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 412 | PRODUCT_BUNDLE_IDENTIFIER = com.raulriera.CacherDemo; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | SWIFT_VERSION = 5.0; 415 | TARGETED_DEVICE_FAMILY = "1,2"; 416 | }; 417 | name = Release; 418 | }; 419 | 4CE8824C1F116D8400A2F3D8 /* Debug */ = { 420 | isa = XCBuildConfiguration; 421 | buildSettings = { 422 | ALWAYS_SEARCH_USER_PATHS = NO; 423 | CLANG_ANALYZER_NONNULL = YES; 424 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 425 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 426 | CLANG_CXX_LIBRARY = "libc++"; 427 | CLANG_ENABLE_MODULES = YES; 428 | CLANG_ENABLE_OBJC_ARC = YES; 429 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 430 | CLANG_WARN_BOOL_CONVERSION = YES; 431 | CLANG_WARN_COMMA = YES; 432 | CLANG_WARN_CONSTANT_CONVERSION = YES; 433 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 434 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 435 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 436 | CLANG_WARN_EMPTY_BODY = YES; 437 | CLANG_WARN_ENUM_CONVERSION = YES; 438 | CLANG_WARN_INFINITE_RECURSION = YES; 439 | CLANG_WARN_INT_CONVERSION = YES; 440 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 441 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 442 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 443 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 444 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 445 | CLANG_WARN_STRICT_PROTOTYPES = YES; 446 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 447 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 448 | CLANG_WARN_UNREACHABLE_CODE = YES; 449 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 450 | CODE_SIGN_IDENTITY = "iPhone Developer"; 451 | COPY_PHASE_STRIP = NO; 452 | CURRENT_PROJECT_VERSION = 1; 453 | DEBUG_INFORMATION_FORMAT = dwarf; 454 | ENABLE_STRICT_OBJC_MSGSEND = YES; 455 | ENABLE_TESTABILITY = YES; 456 | GCC_C_LANGUAGE_STANDARD = gnu11; 457 | GCC_DYNAMIC_NO_PIC = NO; 458 | GCC_NO_COMMON_BLOCKS = YES; 459 | GCC_OPTIMIZATION_LEVEL = 0; 460 | GCC_PREPROCESSOR_DEFINITIONS = ( 461 | "DEBUG=1", 462 | "$(inherited)", 463 | ); 464 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 465 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 466 | GCC_WARN_UNDECLARED_SELECTOR = YES; 467 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 468 | GCC_WARN_UNUSED_FUNCTION = YES; 469 | GCC_WARN_UNUSED_VARIABLE = YES; 470 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 471 | MTL_ENABLE_DEBUG_INFO = YES; 472 | ONLY_ACTIVE_ARCH = YES; 473 | SDKROOT = iphoneos; 474 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 475 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 476 | VERSIONING_SYSTEM = "apple-generic"; 477 | VERSION_INFO_PREFIX = ""; 478 | }; 479 | name = Debug; 480 | }; 481 | 4CE8824D1F116D8400A2F3D8 /* Release */ = { 482 | isa = XCBuildConfiguration; 483 | buildSettings = { 484 | ALWAYS_SEARCH_USER_PATHS = NO; 485 | CLANG_ANALYZER_NONNULL = YES; 486 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 487 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 488 | CLANG_CXX_LIBRARY = "libc++"; 489 | CLANG_ENABLE_MODULES = YES; 490 | CLANG_ENABLE_OBJC_ARC = YES; 491 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 492 | CLANG_WARN_BOOL_CONVERSION = YES; 493 | CLANG_WARN_COMMA = YES; 494 | CLANG_WARN_CONSTANT_CONVERSION = YES; 495 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 496 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 497 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 498 | CLANG_WARN_EMPTY_BODY = YES; 499 | CLANG_WARN_ENUM_CONVERSION = YES; 500 | CLANG_WARN_INFINITE_RECURSION = YES; 501 | CLANG_WARN_INT_CONVERSION = YES; 502 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 503 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 504 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 505 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 506 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 507 | CLANG_WARN_STRICT_PROTOTYPES = YES; 508 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 509 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 510 | CLANG_WARN_UNREACHABLE_CODE = YES; 511 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 512 | CODE_SIGN_IDENTITY = "iPhone Developer"; 513 | COPY_PHASE_STRIP = NO; 514 | CURRENT_PROJECT_VERSION = 1; 515 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 516 | ENABLE_NS_ASSERTIONS = NO; 517 | ENABLE_STRICT_OBJC_MSGSEND = YES; 518 | GCC_C_LANGUAGE_STANDARD = gnu11; 519 | GCC_NO_COMMON_BLOCKS = YES; 520 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 521 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 522 | GCC_WARN_UNDECLARED_SELECTOR = YES; 523 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 524 | GCC_WARN_UNUSED_FUNCTION = YES; 525 | GCC_WARN_UNUSED_VARIABLE = YES; 526 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 527 | MTL_ENABLE_DEBUG_INFO = NO; 528 | SDKROOT = iphoneos; 529 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 530 | VALIDATE_PRODUCT = YES; 531 | VERSIONING_SYSTEM = "apple-generic"; 532 | VERSION_INFO_PREFIX = ""; 533 | }; 534 | name = Release; 535 | }; 536 | 4CE8824F1F116D8400A2F3D8 /* Debug */ = { 537 | isa = XCBuildConfiguration; 538 | buildSettings = { 539 | APPLICATION_EXTENSION_API_ONLY = YES; 540 | CLANG_ENABLE_MODULES = YES; 541 | CODE_SIGN_IDENTITY = ""; 542 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 543 | CODE_SIGN_STYLE = Manual; 544 | DEFINES_MODULE = YES; 545 | DEVELOPMENT_TEAM = ""; 546 | DYLIB_COMPATIBILITY_VERSION = 1; 547 | DYLIB_CURRENT_VERSION = 1; 548 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 549 | INFOPLIST_FILE = "$(SRCROOT)/Sources/Cacher/Info.plist"; 550 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 551 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 552 | MACOSX_DEPLOYMENT_TARGET = 10.11; 553 | PRODUCT_BUNDLE_IDENTIFIER = com.raulriera.Cacher; 554 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 555 | PROVISIONING_PROFILE_SPECIFIER = ""; 556 | SKIP_INSTALL = YES; 557 | SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos watchsimulator watchos macosx"; 558 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 559 | SWIFT_VERSION = 5.0; 560 | TARGETED_DEVICE_FAMILY = "1,2,3,4"; 561 | TVOS_DEPLOYMENT_TARGET = 10.0; 562 | VALID_ARCHS = "x86_64 i386 arm64"; 563 | WATCHOS_DEPLOYMENT_TARGET = 3.0; 564 | }; 565 | name = Debug; 566 | }; 567 | 4CE882501F116D8400A2F3D8 /* Release */ = { 568 | isa = XCBuildConfiguration; 569 | buildSettings = { 570 | APPLICATION_EXTENSION_API_ONLY = YES; 571 | CLANG_ENABLE_MODULES = YES; 572 | CODE_SIGN_IDENTITY = ""; 573 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 574 | CODE_SIGN_STYLE = Manual; 575 | DEFINES_MODULE = YES; 576 | DEVELOPMENT_TEAM = ""; 577 | DYLIB_COMPATIBILITY_VERSION = 1; 578 | DYLIB_CURRENT_VERSION = 1; 579 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 580 | INFOPLIST_FILE = "$(SRCROOT)/Sources/Cacher/Info.plist"; 581 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 582 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 583 | MACOSX_DEPLOYMENT_TARGET = 10.11; 584 | PRODUCT_BUNDLE_IDENTIFIER = com.raulriera.Cacher; 585 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 586 | PROVISIONING_PROFILE_SPECIFIER = ""; 587 | SKIP_INSTALL = YES; 588 | SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos watchsimulator watchos macosx"; 589 | SWIFT_VERSION = 5.0; 590 | TARGETED_DEVICE_FAMILY = "1,2,3,4"; 591 | TVOS_DEPLOYMENT_TARGET = 10.0; 592 | VALID_ARCHS = "x86_64 i386 arm64"; 593 | WATCHOS_DEPLOYMENT_TARGET = 3.0; 594 | }; 595 | name = Release; 596 | }; 597 | 4CE882521F116D8400A2F3D8 /* Debug */ = { 598 | isa = XCBuildConfiguration; 599 | buildSettings = { 600 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 601 | CODE_SIGN_IDENTITY = ""; 602 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 603 | CODE_SIGN_STYLE = Automatic; 604 | DEVELOPMENT_TEAM = ""; 605 | INFOPLIST_FILE = "$(SRCROOT)/Tests/CacherTests/Info.plist"; 606 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks @executable_path/../Frameworks @loader_path/../Frameworks"; 607 | MACOSX_DEPLOYMENT_TARGET = 10.11; 608 | PRODUCT_BUNDLE_IDENTIFIER = com.raulriera.CacherTests; 609 | PRODUCT_NAME = "$(TARGET_NAME)"; 610 | PROVISIONING_PROFILE_SPECIFIER = ""; 611 | SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos watchsimulator watchos macosx"; 612 | SWIFT_VERSION = 4.0; 613 | TARGETED_DEVICE_FAMILY = "1,2,3,4"; 614 | TVOS_DEPLOYMENT_TARGET = 10.0; 615 | VALID_ARCHS = "i386 x86_64"; 616 | WATCHOS_DEPLOYMENT_TARGET = 3.0; 617 | }; 618 | name = Debug; 619 | }; 620 | 4CE882531F116D8400A2F3D8 /* Release */ = { 621 | isa = XCBuildConfiguration; 622 | buildSettings = { 623 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 624 | CODE_SIGN_IDENTITY = ""; 625 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 626 | CODE_SIGN_STYLE = Automatic; 627 | DEVELOPMENT_TEAM = ""; 628 | INFOPLIST_FILE = CacherTests/Info.plist; 629 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks @executable_path/../Frameworks @loader_path/../Frameworks"; 630 | MACOSX_DEPLOYMENT_TARGET = 10.11; 631 | PRODUCT_BUNDLE_IDENTIFIER = com.raulriera.CacherTests; 632 | PRODUCT_NAME = "$(TARGET_NAME)"; 633 | PROVISIONING_PROFILE_SPECIFIER = ""; 634 | SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos watchsimulator watchos macosx"; 635 | SWIFT_VERSION = 4.0; 636 | TARGETED_DEVICE_FAMILY = "1,2,3,4"; 637 | TVOS_DEPLOYMENT_TARGET = 10.0; 638 | VALID_ARCHS = "i386 x86_64"; 639 | WATCHOS_DEPLOYMENT_TARGET = 3.0; 640 | }; 641 | name = Release; 642 | }; 643 | /* End XCBuildConfiguration section */ 644 | 645 | /* Begin XCConfigurationList section */ 646 | 4CB761671F116F9C00E6F9BE /* Build configuration list for PBXNativeTarget "CacherDemo" */ = { 647 | isa = XCConfigurationList; 648 | buildConfigurations = ( 649 | 4CB761681F116F9C00E6F9BE /* Debug */, 650 | 4CB761691F116F9C00E6F9BE /* Release */, 651 | ); 652 | defaultConfigurationIsVisible = 0; 653 | defaultConfigurationName = Release; 654 | }; 655 | 4CE882341F116D8400A2F3D8 /* Build configuration list for PBXProject "Cacher" */ = { 656 | isa = XCConfigurationList; 657 | buildConfigurations = ( 658 | 4CE8824C1F116D8400A2F3D8 /* Debug */, 659 | 4CE8824D1F116D8400A2F3D8 /* Release */, 660 | ); 661 | defaultConfigurationIsVisible = 0; 662 | defaultConfigurationName = Release; 663 | }; 664 | 4CE8824E1F116D8400A2F3D8 /* Build configuration list for PBXNativeTarget "Cacher" */ = { 665 | isa = XCConfigurationList; 666 | buildConfigurations = ( 667 | 4CE8824F1F116D8400A2F3D8 /* Debug */, 668 | 4CE882501F116D8400A2F3D8 /* Release */, 669 | ); 670 | defaultConfigurationIsVisible = 0; 671 | defaultConfigurationName = Release; 672 | }; 673 | 4CE882511F116D8400A2F3D8 /* Build configuration list for PBXNativeTarget "CacherTests" */ = { 674 | isa = XCConfigurationList; 675 | buildConfigurations = ( 676 | 4CE882521F116D8400A2F3D8 /* Debug */, 677 | 4CE882531F116D8400A2F3D8 /* Release */, 678 | ); 679 | defaultConfigurationIsVisible = 0; 680 | defaultConfigurationName = Release; 681 | }; 682 | /* End XCConfigurationList section */ 683 | }; 684 | rootObject = 4CE882311F116D8400A2F3D8 /* Project object */; 685 | } 686 | --------------------------------------------------------------------------------