Inherits from AGBaseStorage : NSObject
Conforms to AGStore
Declared in AGPropertyListStorage.h
AGPropertyListStorage.m

Overview

An AGStore implementation that uses a Property List for storage. It can either use a PLIST or JSON serialization output format depending on type name passed when constructing the Store. If the type is ‘JSON’ the store will use NSJSONSerialization as its backend otherwise it will fell to use NSPropertyListSerialization.

NOTE: You must adhere to the rules governing the serialization of data types for each respective plist type.

IMPORTANT: Users are not required to instantiate this class directly, instead an instance of this class is returned automatically when an DataStore with the type config option is set to “PLIST” or “JSON”. See AGDataManager and AGStore class documentation for more information.

Create a DataManager with a Property List store backend

Below is a small example on how to save to the file system:

// initialize plist store (if the file does not exist it will be created)
AGDataManager* manager = [AGDataManager manager];
id<AGStore> plistStore = [manager store:^(id<AGStoreConfig> config) {
    [config setName:@"secrets"]; // will be used as the filename for the plist
    // specify that a Property List is required and will use the PLIST format as its output
    [config setType:@"PLIST"];  // you can also use 'JSON' to instruct JSON serialization.
}];

// the object to save (e.g. a dictionary)
NSDictionary *otp = [NSDictionary dictionaryWithObjectsAndKeys:@"19a01df0281afcdbe", @"otp", @"1", @"id", nil];

// save it
NSError *error;

if (![plistStore save:otp error:&error])
    NSLog(@"Save: An error occurred during save! \n%@", error);

The read, reset or remove methods found in AGStore behave the same, as on the default (“in memory”) store.

Instance Methods

filter:

Reads all, based on a filter, from the underlying storage system.

- (NSArray *)filter:(NSPredicate *)predicate

Parameters

predicate

The NSPredicate to apply to the data from the underlying storage system.

Return Value

A collection (NSArray), containing all stored objects, matching the given predicate. This method only returns a copy of the data and leaves the underlying storage system intact.

Discussion

Reads all, based on a filter, from the underlying storage system.

Declared In

AGStore.h

isEmpty

Checks if the storage system contains no stored elements.

- (BOOL)isEmpty

Return Value

YES if the storage is empty, otherwise NO.

Discussion

Checks if the storage system contains no stored elements.

Declared In

AGStore.h

read:

Reads a specific object/record from the underlying storage system.

- (id)read:(id)recordId

Parameters

recordId

id from the desired object.

Return Value

The object (or nil) read from the underlying storage.

Discussion

Reads a specific object/record from the underlying storage system.

Declared In

AGStore.h

readAll

Reads all the data from the underlying storage system.

- (NSArray *)readAll

Return Value

A collection (NSArray), containing all stored objects.

Discussion

Reads all the data from the underlying storage system.

Declared In

AGStore.h

remove:error:

Removes a specific object/record from the underlying storage system.

- (BOOL)remove:(id)record error:(NSError **)error

Parameters

record

the desired object

error

An error object containing details of why the remove failed.

Return Value

YES if the operation succeeds, otherwise NO.

Discussion

Removes a specific object/record from the underlying storage system.

Declared In

AGStore.h

reset:

Resets the entire storage system.

- (BOOL)reset:(NSError **)error

Parameters

error

An error object containing details of why the reset failed.

Return Value

YES if the operation succeeds, otherwise NO.

Discussion

Resets the entire storage system.

Declared In

AGStore.h

save:error:

Saves the given object in the underlying storage system.

- (BOOL)save:(id)data error:(NSError **)error

Parameters

data

A mutable dictionary representing key/value, dictionary must be mutable as id is optional and can be added after being saved. Data can also be a collection (e.g. NSArray) of mutable dictionary. This parameter is the object being persisted.

error

An error object containing details of why the save failed.

Return Value

YES if the operation succeeds, otherwise NO.

Discussion

Saves the given object in the underlying storage system.

Declared In

AGStore.h