Latest 1.0.0
Homepage https://github.com/xinminlabs/SerializedUser
License MIT
Dependencies SSKeychain
Authors

Serialize user with NSUserDefaults and save sensitive token with SSKeychain.

Adding to Your Project

Simply add the following to your Podfile.

pod 'SerializedUser'

Working with the SerializedUser

SerializedUser provides the following class methods.

+ (instancetype)currentUser;
+ (BOOL)isUserLoggedIn;

SerializedUser also provides an instance method.

- (void)persist;

SerializedUser adds a property.

@property (nonatomic, strong) NSString *token;

Example

1. You should create your own user model and extend SerializedUser

#import "SerializedUser.h"

@interface CLUser : SerializedUser

@property (nonatomic, strong) NSString *email;
@end
#import "CLUser.h"

@implementation CLUser

- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:self.email forKey:@"email"];
}

- (id)initWithCoder:(NSCoder *)decoder {
    self = [super init];
    if (self) {
        self.email = [decoder decodeObjectForKey:@"email"];
    }
    return self;
}

@end

2. Then you can persist user.

CLUser *user = [[CLUser alloc] init];
user.email = @"[email protected]";
user.token = @"access_token";
[user persist];

3. And get current user.

if ([CLUser isLoggedIn]) {
  [CLUser currentUser].email;
  [CLUser currentUser].token;
}

Latest podspec

{
    "name": "SerializedUser",
    "version": "1.0.0",
    "summary": "Serialize user with NSUserDefaults and save sensitive token with SSKeychain",
    "homepage": "https://github.com/xinminlabs/SerializedUser",
    "authors": {
        "Richard Huang": "[email protected]"
    },
    "source": {
        "git": "https://github.com/xinminlabs/SerializedUser.git",
        "tag": "v1.0.0"
    },
    "source_files": "SerializedUser/*.{h,m}",
    "requires_arc": true,
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "dependencies": {
        "SSKeychain": []
    }
}

Pin It on Pinterest

Share This