A-IOSHelper [Animax Helper]

This is a scaffold library and the aid of the project is providing all foundation functions for IOS developer to build app easier.
Stories in Ready Build Status


Project maintained by Animaxx Thanks mattgraham for original Theme

Data model

When an object inherited 'A_DataModel', then it able to save the instance to plist file or sqlite database directly.

Contents

Demo model

    // ModelTest.h file
    #import <A_IOSHelper/A_IOSHelper.h>

    @interface TestDataModel : A_DataModel

    @property (retain, nonatomic) NSString* Name;
    @property (retain, nonatomic) NSDate* CreateDate;
    @property (nonatomic) NSInteger Index;
    @property (retain, nonatomic) NSNumber* ID;

    @end

Save model to Plist file

    TestDataModel* _model1 = [[TestDataModel alloc] init];
    [_model1 setName:@"Object_1"];
    [_model1 setCreateDate: [NSDate date]];
    [_model1 setID:@0];
    [_model1 A_SaveToPlist];

Get models in plist

    NSArray* models = [TestDataModel A_GetFromPliste]; 

Delete model in plist

    TestDataModel* _model = [[TestDataModel alloc] init];
    [_model setIndex:1];
    [_model setName:@"Object_1"];
    [_model setCreateDate: [NSDate date]];
    [_model setID:@1];
    [_model A_SaveToPlist]; // The model has been saved.
    [_model A_DeleteInPlist]; 

Clear models in plist

This function only clear same type of models. For example, using [TestDataModel A_ClearFromPlist]; will clear only TestDataModels.

 [TestDataModel A_ClearFromPlist]; 

Save models to Sqlite

This function will automatically generate Table if the table isn't exist in Sqlite.

     TestDataModel* _model = [[TestDataModel alloc] init];
    [_model setIndex:0];
    [_model setName:@"Object_1"];
    [_model setCreateDate: [NSDate date]];
    [_model setID:@0];
    [_model A_SaveToSqlite];

Search models from Sqlite

Searching certain type of models in Sqlite

    NSArray* _ models = [TestDataModel A_SearchSqlite:@"`name` like '%object%'"];

OR

    [TestDataModel A_SearchSqlite:@"" withBlock:^(id obj, NSArray *result) {
        // TODO: Other operations with data result
        //obj is self.view
    } andArg:self.view];

Search similar models from Sqlite

Searching certain type of models with demo model.

    TestDataModel* _model = [[TestDataModel alloc] init];
    [_model setIndex:0];

    // Searching models with index == 0
    NSArray* _models =[_model A_SearchSimilarModelsInSqlite];
    // OR
    [_model1 A_SearchSimilarModelsInSqliteWithBlock:^(id obj, NSArray *result) {
        XCTAssertTrue(result.count >= 1);
    } andArg:nil];