Swiftpack.co - Package - dkoster95/PelicanSwift

  • Simple Way to manage your local storage
  • Persistence Module
  • Keep local storage simple

Swift Persistence framework.

Your app usually uses local storage to store tokens, offline data or user preferences. Pelican is a framework created to handle those requirements by using a repository pattern. There are 3 repository implementations Keychain, CoreData and UserDefaults. If you have diferent requirements or wanna use a diferent type of persistence you can create your own repository by extending PelicanRepository class!
The framework also provides a Keychain Wrapper in case you dont want to use the repository pattern.


open class PelicanRepository <PersistibleObject: Any> {
    
    open func empty() {}
    
    open var isEmpty: Bool { return fetchAll.isEmpty }
    
    public init() {}
    
    open var fetchAll: [PersistibleObject] {
        return []
    }
    
    open func save(object: PersistibleObject) -> Bool {
        return true
    }
    
    open func update(object: PersistibleObject) -> Bool {
        return true
    }
    
    open func save() -> Bool {
        return true
    }
    
    open func filter(query: (PersistibleObject) -> Bool) -> [PersistibleObject] { return fetchAll.filter { query($0) }
    }
    
    open func delete(object: PersistibleObject) -> Bool {
        return true
    }
    
    open var first: PersistibleObject? {
        return fetchAll.first
    }
}

Here you have the Pelican Repository class definition, It was made a class instead of a protocol because it uses a generic type and swift associatedTypes with protocols are not friendly :(.
Those are all the features a Repository should have: add, removing, empty, and the fetching options.
if you want your own repository implementation you just need to make your class extend this repository class and then override the methods you want!

Repositories


Requirements

  • iOS 11.0+
  • WatchOS 5.0+
  • TvOS 12.0+
  • MacOS 10.12+
  • Xcode 10.2+
  • Swift 5+

Installation

### Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate Pelican into your Xcode project using Carthage, specify it in your Cartfile:

git "https://github.com/dkoster95/PelicanSwift.git" "1.0"

Run carthage update to build the framework (you can specify the platform) and then drag the executable Pelican.framework into your Xcode project.

Manually

No Package manager? no problem, you can use Pelican as a git submodule

Swift Package Manager

QuickHatch has support for SPM, you just need to go to Xcode in the menu File/Swift Packages/Add package dependency and you select the version of Pelican.

Embedded Framework

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:

    $ git init
    
  • Add Pelican as a git submodule by running the following command:

    $ git submodule add https://github.com/dkoster95/PelicanSwift.git
    
  • Open the new PelicanSwift folder, and drag the PelicanSwift.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the PelicanSwift.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • And that's it!


Github

link
Stars: 1

Dependencies

Used By

Total: 0

Releases

InMemory Repository - 2020-09-22 20:19:40

update, isEmpty and filter features - 2020-09-22 20:01:43

Package Updates - 2020-09-15 15:41:25

SPA support - 2020-09-15 15:32:06

First Release - 2020-01-21 21:13:26

Pelican Framework

  • Supported for iOS, MacOS, WatchOS and TvOS