Skip to content
/ Loper Public

Swift key value store, backed by SQLite

License

Notifications You must be signed in to change notification settings

markmunz/Loper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Loper

Local Persistent Store is a Key Value store for iOS. It's written in Swift but fully compatable with Objective-C.


Getting Started

Open the store and prepare it for writing:

NSError *error = nil;
if (![[LOPStore defaultStore] openAndReturnError:&error]) {
  // Super good error handling
}

Write a value:

NSString *name = @"Loper";
[[LOPStore defaultStore] setObject:name forKey:@"project_name" inScope:nil];

Reading a value:

NSString *name = [[LOPStore defaultStore] stringForKey:@"project_name" inScope:nil];

If the value isn't found nil will be returned.

Scopes

Scopes allow you to manage a group of keys. E.G.

[[LOPStore defaultStore] setObject@"[email protected]" forKey:@"email" inScope:@"logged_in"];

// User logs out

NSError *error = nil;
if (![[LOPStore defaultStore] deleteScope:@"logged_in" error:&error]) {
  // Super good error handling
}

NSString *email = [[LOPStore defaultStore] stringForKey:@"email" inScope:@"logged_in"];
// email == nil

This will delete all values with the logged_in scope.

If nil is passed to scope then [LOPStore scope] will be used. Keys MUST be unique for a scope. So setting foo : nil a second time will replace the original value in the store. But setting foo : bar will insert a new value into the bar scope and keep the default scope value intact.

Cleanup

Because Loper is backed by a SQLite database occasionally you'll need to run cleanup to repack the database file if your keys are volatile.

NSError *error = nil;
if (![[LOPStore defaultStore] cleanupAndReturnError:&error]) {
  // Super good error handling
}

This operation can be slow and should occure on a background thread. All reads & writes to the store will be blocked until this operation is completed.

About

Swift key value store, backed by SQLite

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages