- Fix Vari

This commit is contained in:
Giuseppe Nucifora 2016-01-26 00:29:37 +01:00
parent f569c8545c
commit 7e5a6149a8
28 changed files with 1162 additions and 862 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="whP-gf-Uak"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="whP-gf-Uak">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>

View File

@ -9,6 +9,7 @@
#import "PNObjectAppDelegate.h" #import "PNObjectAppDelegate.h"
#import "PNObject.h" #import "PNObject.h"
#import "PNUser.h" #import "PNUser.h"
#import "PNAddress.h"
@implementation PNObjectAppDelegate @implementation PNObjectAppDelegate
@ -27,14 +28,40 @@
//[PNObject get];*/ //[PNObject get];*/
PNUser *user = [PNUser currentUser]; PNUser *user = [PNUser currentUser];
[user setFirstName:@"peppe"];
[user setLastName:@"nucifora"];
[user setUsername:@"giuseppe.nucifora"];
[user setPassword:@"giuseppe.nucifora.password"];
PNUser *object = [user saveLocally];
NSLog(@"User : %@",[object getObject]); NSLog(@"asd");
/*[user setFirstName:@"Giuseppe"];
[user setLastName:@"Nucifora"];
[user setHasAcceptedNewsletter:YES];
[user setHasAcceptedPrivacy:YES];
[user setUsername:@"giuseppe.nucifora"];
[user setPassword:@"giuseppe.nucifora.password"];
[user setPhone:@"+393485904995"];
[user saveLocally];
*/
//NSLog(@"%@",[user getObject]);
/*
PNAddress *address1 = [[PNAddress alloc] init];
[address1 setZip:@"95014"];
[address1 setCountry:@"Italy"];
[address1 setCity:@"Giarre"];
[address1 setProvince:@"Catania"];
NSLog(@"%@",[address1 saveLocally]);
PNAddress *address2 = [[PNAddress alloc] init];
[address2 setZip:@"95014"];
[address2 setCountry:@"Italy"];
[address2 setCity:@"Giarre"];
[address2 setProvince:@"Catania"];
NSLog(@"%@",[address2 saveLocally]);*/
return YES; return YES;
} }

View File

@ -25,7 +25,7 @@ PODS:
- FBSnapshotTestCase/SwiftSupport (2.0.7): - FBSnapshotTestCase/SwiftSupport (2.0.7):
- FBSnapshotTestCase/Core - FBSnapshotTestCase/Core
- NSDate_Utils (0.1.0) - NSDate_Utils (0.1.0)
- NSString-Helper (1.0.1) - NSString-Helper (1.0.2)
- nv-ios-http-status (0.0.1) - nv-ios-http-status (0.0.1)
- PEAR-FileManager-iOS (1.3.1) - PEAR-FileManager-iOS (1.3.1)
- PNObject (0.1.0): - PNObject (0.1.0):
@ -38,7 +38,7 @@ PODS:
- UIDevice-Utils - UIDevice-Utils
- Specta (1.0.5) - Specta (1.0.5)
- StrongestPasswordValidator (0.1.1) - StrongestPasswordValidator (0.1.1)
- UIDevice-Utils (0.1.2) - UIDevice-Utils (0.1.4)
DEPENDENCIES: DEPENDENCIES:
- AFNetworking - AFNetworking
@ -66,13 +66,13 @@ SPEC CHECKSUMS:
Expecta+Snapshots: 29b38dd695bc72a0ed2bea833937d78df41943ba Expecta+Snapshots: 29b38dd695bc72a0ed2bea833937d78df41943ba
FBSnapshotTestCase: 7e85180d0d141a0cf472352edda7e80d7eaeb547 FBSnapshotTestCase: 7e85180d0d141a0cf472352edda7e80d7eaeb547
NSDate_Utils: 4a57f91094123d5b7600c7de8c9ad9e1d43306a3 NSDate_Utils: 4a57f91094123d5b7600c7de8c9ad9e1d43306a3
NSString-Helper: e26909c87694add9be022ca24e856e3b6148fe89 NSString-Helper: 0ee74919829a332f9838fa87b28cb2d1d991e92c
nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f
PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3
PNObject: b71ba455c15aedd1233cdf02bcf65d348d96da72 PNObject: b71ba455c15aedd1233cdf02bcf65d348d96da72
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b
UIDevice-Utils: 14362004e88f8cc05d8ec68369724a5972faadec UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4
PODFILE CHECKSUM: 3d7d9ec922a37131d59224a7700af30168ea90b1 PODFILE CHECKSUM: 3d7d9ec922a37131d59224a7700af30168ea90b1

View File

@ -25,7 +25,7 @@ PODS:
- FBSnapshotTestCase/SwiftSupport (2.0.7): - FBSnapshotTestCase/SwiftSupport (2.0.7):
- FBSnapshotTestCase/Core - FBSnapshotTestCase/Core
- NSDate_Utils (0.1.0) - NSDate_Utils (0.1.0)
- NSString-Helper (1.0.1) - NSString-Helper (1.0.2)
- nv-ios-http-status (0.0.1) - nv-ios-http-status (0.0.1)
- PEAR-FileManager-iOS (1.3.1) - PEAR-FileManager-iOS (1.3.1)
- PNObject (0.1.0): - PNObject (0.1.0):
@ -38,7 +38,7 @@ PODS:
- UIDevice-Utils - UIDevice-Utils
- Specta (1.0.5) - Specta (1.0.5)
- StrongestPasswordValidator (0.1.1) - StrongestPasswordValidator (0.1.1)
- UIDevice-Utils (0.1.2) - UIDevice-Utils (0.1.4)
DEPENDENCIES: DEPENDENCIES:
- AFNetworking - AFNetworking
@ -66,13 +66,13 @@ SPEC CHECKSUMS:
Expecta+Snapshots: 29b38dd695bc72a0ed2bea833937d78df41943ba Expecta+Snapshots: 29b38dd695bc72a0ed2bea833937d78df41943ba
FBSnapshotTestCase: 7e85180d0d141a0cf472352edda7e80d7eaeb547 FBSnapshotTestCase: 7e85180d0d141a0cf472352edda7e80d7eaeb547
NSDate_Utils: 4a57f91094123d5b7600c7de8c9ad9e1d43306a3 NSDate_Utils: 4a57f91094123d5b7600c7de8c9ad9e1d43306a3
NSString-Helper: e26909c87694add9be022ca24e856e3b6148fe89 NSString-Helper: 0ee74919829a332f9838fa87b28cb2d1d991e92c
nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f
PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3
PNObject: b71ba455c15aedd1233cdf02bcf65d348d96da72 PNObject: b71ba455c15aedd1233cdf02bcf65d348d96da72
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b
UIDevice-Utils: 14362004e88f8cc05d8ec68369724a5972faadec UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4
PODFILE CHECKSUM: 3d7d9ec922a37131d59224a7700af30168ea90b1 PODFILE CHECKSUM: 3d7d9ec922a37131d59224a7700af30168ea90b1

View File

@ -14,6 +14,8 @@
- (BOOL) isNumeric; - (BOOL) isNumeric;
- (BOOL) isValidPhoneNumber;
- (BOOL) isValidUrl; - (BOOL) isValidUrl;
- (BOOL) isValidTaxCode; - (BOOL) isValidTaxCode;

View File

@ -28,6 +28,22 @@
return isValid; return isValid;
} }
- (BOOL) isValidPhoneNumber {
NSError *error = NULL;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypePhoneNumber error:&error];
NSArray *matches = [detector matchesInString:self options:0 range:NSMakeRange(0, [self length])];
if (matches != nil) {
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypePhoneNumber) {
return YES;
}
}
}
return NO;
}
- (BOOL) isValidUrl { - (BOOL) isValidUrl {
NSString *urlRegEx = NSString *urlRegEx =
@"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+"; @"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";

View File

@ -17,19 +17,20 @@ NSString-Helper is available through [CocoaPods](http://cocoapods.org). To insta
it, simply add the following line to your Podfile: it, simply add the following line to your Podfile:
```ruby ```ruby
pod 'NSString-Helper' , :git => 'https://github.com/giuseppenucifora/NSString-Helper.git'
OR
pod 'NSString-Helper' pod 'NSString-Helper'
``` ```
##Usage ##Usage
```ruby ```ruby
#import <NSString-Helper/NSString+Helper.h>
NSString *str = @"testCode"; NSString *str = @"testCode";
NSLog(@"%@",[NSNumber numberWithBool:[str isNumeric]]); NSLog(@"%@",[NSNumber numberWithBool:[str isNumeric]]);
NSLog(@"%@",[NSNumber numberWithBool:[str isValidPhoneNumber]]);
NSLog(@"%@",[NSNumber numberWithBool:[str isValidEmail]]); NSLog(@"%@",[NSNumber numberWithBool:[str isValidEmail]]);
NSLog(@"%@",[NSNumber numberWithBool:[str isValidUrl]]); NSLog(@"%@",[NSNumber numberWithBool:[str isValidUrl]]);

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
buildForArchiving = "YES"> buildForArchiving = "YES">
<BuildableReference <BuildableReference
BuildableIdentifier = 'primary' BuildableIdentifier = 'primary'
BlueprintIdentifier = 'ECB7C6AA04CE9C3E543F286B' BlueprintIdentifier = '4FB4437C636DCECA1396EC4C'
BlueprintName = 'PNObject' BlueprintName = 'PNObject'
ReferencedContainer = 'container:Pods.xcodeproj' ReferencedContainer = 'container:Pods.xcodeproj'
BuildableName = 'PNObject.framework'> BuildableName = 'PNObject.framework'>

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0.1</string> <string>1.0.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>

View File

@ -13,7 +13,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>BNDL</string> <string>BNDL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0.1</string> <string>1.0.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>

View File

@ -1,5 +1,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "PNObject+PNObjectConnection.h"
#import "PNObject+Protected.h"
#import "PNObject.h" #import "PNObject.h"
#import "PNObjectConfig.h" #import "PNObjectConfig.h"
#import "PNObjectConstants.h" #import "PNObjectConstants.h"

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.1.2</string> <string>0.1.4</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>

View File

@ -13,7 +13,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>BNDL</string> <string>BNDL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.1.2</string> <string>0.1.4</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>

View File

@ -73,6 +73,13 @@ typedef NS_ENUM(NSUInteger, UIDeviceModelInches) {
UIDeviceModelInches79, UIDeviceModelInches79,
UIDeviceModelInches97, UIDeviceModelInches97,
UIDeviceModelInches129, UIDeviceModelInches129,
UIDeviceSimulatorModelInches35 = UIDeviceModelInches35,
UIDeviceSimulatorModelInches4 = UIDeviceModelInches4,
UIDeviceSimulatorModelInches47 = UIDeviceModelInches47,
UIDeviceSimulatorModelInches55 = UIDeviceModelInches55,
UIDeviceSimulatorModelInches79 = UIDeviceModelInches79,
UIDeviceSimulatorModelInches97 = UIDeviceModelInches97,
UIDeviceSimulatorModelInches129 = UIDeviceModelInches129,
UIDeviceModelInchesUnKnown UIDeviceModelInchesUnKnown
}; };

View File

@ -171,6 +171,8 @@
if ([modelIdentifier isEqualToString:@"iPad4,2"]) return UIDeviceGenerationModeliPadAir; if ([modelIdentifier isEqualToString:@"iPad4,2"]) return UIDeviceGenerationModeliPadAir;
if ([modelIdentifier isEqualToString:@"iPad5,3"]) return UIDeviceGenerationModeliPadAir2; if ([modelIdentifier isEqualToString:@"iPad5,3"]) return UIDeviceGenerationModeliPadAir2;
if ([modelIdentifier isEqualToString:@"iPad5,4"]) return UIDeviceGenerationModeliPadAir2; if ([modelIdentifier isEqualToString:@"iPad5,4"]) return UIDeviceGenerationModeliPadAir2;
if ([modelIdentifier isEqualToString:@"iPad6,7"]) return UIDeviceGenerationModeliPadPro;
if ([modelIdentifier isEqualToString:@"iPad6,8"]) return UIDeviceGenerationModeliPadPro;
// iPad Mini http://theiphonewiki.com/wiki/IPad_mini // iPad Mini http://theiphonewiki.com/wiki/IPad_mini
@ -203,8 +205,14 @@
if ([modelIdentifier hasSuffix:@"86"] || [modelIdentifier isEqual:@"x86_64"]) if ([modelIdentifier hasSuffix:@"86"] || [modelIdentifier isEqual:@"x86_64"])
{ {
BOOL smallerScreen = ([[UIScreen mainScreen] bounds].size.width < 768.0); BOOL iPhoneScreen = ([[UIScreen mainScreen] bounds].size.width < 768.0);
return (smallerScreen ? UIDeviceGenerationModeliPhoneSimulator : UIDeviceGenerationModeliPadSimulator); BOOL iPadScreen = !iPhoneScreen;
if (iPadScreen) {
return UIDeviceGenerationModeliPadSimulator;
}
else {
return UIDeviceGenerationModeliPhoneSimulator;
}
} }
return UIDeviceGenerationModelUnknown; return UIDeviceGenerationModelUnknown;
} }
@ -250,6 +258,9 @@
if ([modelIdentifier isEqualToString:@"iPad5,3"]) return @"iPad Air 2 (Wi-Fi)"; if ([modelIdentifier isEqualToString:@"iPad5,3"]) return @"iPad Air 2 (Wi-Fi)";
if ([modelIdentifier isEqualToString:@"iPad5,4"]) return @"iPad Air 2 (Cellular)"; if ([modelIdentifier isEqualToString:@"iPad5,4"]) return @"iPad Air 2 (Cellular)";
if ([modelIdentifier isEqualToString:@"iPad6,7"]) return @"iPad Pro (Wi-Fi)";
if ([modelIdentifier isEqualToString:@"iPad6,8"]) return @"iPad Pro (Cellular)";
// iPad Mini http://theiphonewiki.com/wiki/IPad_mini // iPad Mini http://theiphonewiki.com/wiki/IPad_mini
if ([modelIdentifier isEqualToString:@"iPad2,5"]) return @"iPad mini 1G (Wi-Fi)"; if ([modelIdentifier isEqualToString:@"iPad2,5"]) return @"iPad mini 1G (Wi-Fi)";
@ -320,23 +331,62 @@
case UIDeviceGenerationModeliPad4: case UIDeviceGenerationModeliPad4:
case UIDeviceGenerationModeliPadAir: case UIDeviceGenerationModeliPadAir:
case UIDeviceGenerationModeliPadAir2:{ case UIDeviceGenerationModeliPadAir2:{
return UIDeviceModelInches97; return UIDeviceModelInches97;
} }
break; break;
case UIDeviceGenerationModeliPadMini1: case UIDeviceGenerationModeliPadMini1:
case UIDeviceGenerationModeliPadMini2: case UIDeviceGenerationModeliPadMini2:
case UIDeviceGenerationModeliPadMini3: case UIDeviceGenerationModeliPadMini3:
case UIDeviceGenerationModeliPadMini4: case UIDeviceGenerationModeliPadMini4:{
{
return UIDeviceModelInches79; return UIDeviceModelInches79;
} }
break; break;
case UIDeviceGenerationModeliPadPro:{ case UIDeviceGenerationModeliPadPro:{
return UIDeviceModelInches129; return UIDeviceModelInches129;
}
default:
break; break;
}
case UIDeviceGenerationModeliPadSimulator:
case UIDeviceGenerationModeliPhoneSimulator:{
CGRect screenRect = [[UIScreen mainScreen] bounds];
NSInteger screenHeight = ((NSInteger)screenRect.size.height > (NSInteger)screenRect.size.width) ? (NSInteger)screenRect.size.height : (NSInteger)screenRect.size.width;
switch (screenHeight) {
case 480:{
return UIDeviceSimulatorModelInches35;
}
break;
case 568:{
return UIDeviceSimulatorModelInches4;
break;
}
case 667:{
return UIDeviceSimulatorModelInches47;
break;
}
case 736:{
return UIDeviceSimulatorModelInches55;
break;
}
case 1024:{
return UIDeviceModelInches97;
break;
}
case 1366:{
return UIDeviceSimulatorModelInches129;
break;
}
default:{
return UIDeviceModelInchesUnKnown;
break;
}
}
break;
}
default: {
return UIDeviceModelInchesUnKnown;
break;
}
} }
return UIDeviceModelInchesUnKnown; return UIDeviceModelInchesUnKnown;
} }

View File

@ -17,10 +17,6 @@ UIDevice-Utils is available through [CocoaPods](http://cocoapods.org). To instal
it, simply add the following line to your Podfile: it, simply add the following line to your Podfile:
```ruby ```ruby
pod "UIDevice-Utils" , :git => 'https://github.com/giuseppenucifora/UIDevice-Utils.git'
or
pod "UIDevice-Utils" pod "UIDevice-Utils"
``` ```

View File

@ -12,7 +12,7 @@
#import "PNObjectConfig.h" #import "PNObjectConfig.h"
#import "PNObjectModel.h" #import "PNObjectModel.h"
#import <AFNetworking/AFNetworking.h> #import <AFNetworking/AFNetworking.h>
#import "PNObject.m" #import "PNObject+Protected.h"
@implementation PNObject (PNObjectConnection) @implementation PNObject (PNObjectConnection)
@ -28,7 +28,7 @@
NSLogDebug(@"JSON: %@", responseObject); NSLogDebug(@"JSON: %@", responseObject);
NSLogDebug(@"JSON: %@", [responseObject class]); NSLogDebug(@"JSON: %@", [responseObject class]);
_JSON = [[NSDictionary alloc] initWithDictionary:responseObject]; self.JSON = [[NSDictionary alloc] initWithDictionary:responseObject];
[self populateObjectFromJSON:responseObject]; [self populateObjectFromJSON:responseObject];
@ -38,10 +38,6 @@
NSLogDebug(@"Error: %@", error); NSLogDebug(@"Error: %@", error);
}]; }];
} }

View File

@ -0,0 +1,30 @@
//
// PNObject+Protected.h
// Pods
//
// Created by Giuseppe Nucifora on 25/01/16.
//
//
#import <PNObject/PNObject.h>
#import <objc/runtime.h>
@interface PNObject (Protected)
@property (nonatomic, strong) PNObjectModel * _Nonnull objectModel;
@property (nonatomic, strong) NSDictionary * _Nonnull JSON;
@property (nonatomic, strong) NSString * _Nonnull endPoint;
@property (nonatomic) BOOL singleInstance;
- (void)populateObjectFromJSON:(id _Nullable)JSON;
- (BOOL)isStringNull:(NSString * _Nullable)str;
- (BOOL)isObjNull:(id _Nullable)obj;
+ (NSArray * _Nonnull) protectedProperties;
@end

View File

@ -0,0 +1,150 @@
//
// PNObject+Protected.m
// Pods
//
// Created by Giuseppe Nucifora on 25/01/16.
//
//
#import "PNObject+Protected.h"
#import <PNObjectProperty.h>
#import "PNObjectConstants.h"
#import <NSDate_Utils/NSDate+NSDate_Util.h>
@implementation PNObject (Protected)
@dynamic endPoint;
@dynamic objectModel;
@dynamic JSON;
@dynamic singleInstance;
+ (NSArray * _Nonnull) protectedProperties {
return @[@"JSON",@"subClassDelegate",@"objectModel",@"objectMapping"];
}
- (void)populateObjectFromJSON:(id _Nullable)JSON
{
NSDictionary *properties = [PNObjectProperty propertiesForClass:self.class];
for(NSString *propertyName in properties) {
if([propertyName isEqualToString:@"mappingError"])
continue;
NSString *mappedJSONKey;
NSString *mappedJSONType;
NSString *propertyType = [properties valueForKey:propertyName];
id mappingValue = [self.objectMapping valueForKey:propertyName];
if([mappingValue isKindOfClass:NSDictionary.class]) {
mappedJSONKey = [mappingValue valueForKey:@"key"];
mappedJSONType = [mappingValue valueForKey:@"type"];
} else {
mappedJSONKey = mappingValue;
}
// Check if there is mapping for the property
if([self isObjNull:mappedJSONKey]) {
// No mapping so just continue
continue;
}
// Get JSON value for the mapped key
id value = [JSON valueForKeyPath:propertyName];
if([self isObjNull:value]) {
continue;
}
((void (^)())@{
@"c" : ^{
char val = [value charValue];
[self setValue:@(val) forKey:propertyName];
},
@"d" : ^{
double val = [value doubleValue];
[self setValue:@(val) forKey:propertyName];
},
@"f" : ^{
float val = [value floatValue];
[self setValue:@(val) forKey:propertyName];
},
@"i" : ^{
int val = [value intValue];
[self setValue:@(val) forKey:propertyName];
},
@"l" : ^{
long val = [value longValue];
[self setValue:@(val) forKey:propertyName];
},
@"s" : ^{
short val = [value shortValue];
[self setValue:@(val) forKey:propertyName];
},
@"B" : ^{
BOOL val = [value boolValue];
[self setValue:@(val) forKey:propertyName];
},
@"NSString" : ^{
NSString *val = [NSString stringWithFormat:@"%@", value];
if (![self isObjNull:val]) {
[self setValue:val forKey:propertyName];
}
},
@"NSNumber" : ^{
NSInteger val = [value integerValue];
[self setValue:@(val) forKey:propertyName];
},
@"NSDate" : ^{
NSString *str = [NSString stringWithFormat:@"%@", value];
NSDate *val = [[NSDate dateFromString:str withFormat:kNSDateHelperFormatSQLDateWithTime] toLocalTime];
if (![self isObjNull:val]) {
[self setValue:val forKey:propertyName];
}
},
@"NSArray" : ^{
NSMutableArray *arr = [NSMutableArray array];
for(id JSONObject in value) {
PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject];
[arr addObject:val];
}
[self setValue:arr forKey:propertyName];
},
@"NSMutableArray" : ^{
NSMutableArray *arr = [NSMutableArray array];
for(id JSONObject in value) {
PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject];
[arr addObject:val];
}
[self setValue:arr forKey:propertyName];
}
}[propertyType] ?: ^{
BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
PNObject *val = [[NSClassFromString(propertyType) alloc] initWithJSON:value];
[self setValue:val forKey:propertyName];
}
else {
NSString *errorStr = [NSString stringWithFormat:@"Property '%@' could not be assigned any value.", propertyName];
NSLogDebug(@"%@",errorStr);
}
})();
}
}
- (BOOL)isObjNull:(id _Nullable)obj
{
if(!obj || nil == obj || NSNull.null == obj || ([obj isKindOfClass:[NSString class]] && [obj isEqualToString:@"(null)"]) || [obj isEqual:[NSNull null]])
return YES;
else
return NO;
}
@end

View File

@ -27,7 +27,7 @@
@interface PNObject : NSObject @interface PNObject : NSObject
@property (nonatomic, strong) NSString * _Nonnull objID; @property (nonatomic, strong) NSString * _Nonnull objID;
@property (nonatomic, strong) NSDate * _Nonnull createdDate; @property (nonatomic, strong) NSDate * _Nonnull createdAt;
@property (nonatomic, strong, getter=getObject) NSDictionary * _Nonnull objectMapping; @property (nonatomic, strong, getter=getObject) NSDictionary * _Nonnull objectMapping;
@property (nonatomic, assign) id<PNObjectSubclassing> _Nonnull subClassDelegate; @property (nonatomic, assign) id<PNObjectSubclassing> _Nonnull subClassDelegate;
@ -35,6 +35,4 @@
- (id _Nonnull) saveLocally; - (id _Nonnull) saveLocally;
- (void) saveLocallyInBackGroundWithBlock:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock;
@end @end

View File

@ -12,18 +12,18 @@
#import <AFNetworking/AFNetworking.h> #import <AFNetworking/AFNetworking.h>
#import "PNObject/PNUser.h" #import "PNObject/PNUser.h"
#import "PNObjectConstants.h" #import "PNObjectConstants.h"
#import "PNObject+Protected.h"
#define PNOBJECT_DIR @"PNObjects" #define PNOBJECT_DIR @"PNObjects"
@interface PNObject() <PNObjectPersistency> @interface PNObject() <PNObjectPersistency>
@property (nonatomic, strong) PNObjectModel *objectModel; @property (nonatomic, strong) PNObjectModel * _Nonnull objectModel;
@property (nonatomic, strong) NSDictionary *JSON; @property (nonatomic, strong) NSMutableDictionary * _Nonnull JSON;
@property (nonatomic, strong) NSString *endPoint; @property (nonatomic, strong) NSString * _Nonnull endPoint;
@property (nonatomic) BOOL singleInstance; @property (nonatomic) BOOL singleInstance;
@ -31,15 +31,26 @@
@implementation PNObject @implementation PNObject
- (NSDictionary *) PNObjectMapping {
NSDictionary *mapping = @{@"objID":@"objID",
@"createdAt":@"created_at",
};
return mapping;
}
- (instancetype) init { - (_Nullable instancetype) init {
self = [super init]; self = [super init];
if (self) { if (self) {
if ([[self class] isSubclassOfClass:[PNObject class]]) { if ([[self class] isSubclassOfClass:[PNObject class]]) {
NSAssert([[self class] conformsToProtocol:@protocol(PNObjectSubclassing)], @"Subclass object must conform to PNObjectSubclassing"); NSAssert([[self class] conformsToProtocol:@protocol(PNObjectSubclassing)], @"Subclass object must conform to PNObjectSubclassing");
_objectMapping = [[self class] objcetMapping]; _objID = [[NSProcessInfo processInfo] globallyUniqueString];
NSMutableDictionary * objectDict = [[NSMutableDictionary alloc] initWithDictionary:[[self class] objcetMapping]];
[objectDict addEntriesFromDictionary:[self PNObjectMapping]];
_objectMapping = objectDict;
NSAssert(_objectMapping, @"You must create objectMapping"); NSAssert(_objectMapping, @"You must create objectMapping");
@ -47,40 +58,26 @@
_objectModel = [PNObjectModel sharedInstance]; _objectModel = [PNObjectModel sharedInstance];
[_objectModel setPersistencyDelegate:self]; [_objectModel setPersistencyDelegate:self];
_createdAt = [[NSDate date] toLocalTime];
} }
} }
return self; return self;
} }
- (instancetype) initWithJSON:(NSDictionary*) JSON { - (_Nullable instancetype) initWithJSON:( NSDictionary * _Nonnull) JSON {
self = [self init]; self = [self init];
if (self) { if (self) {
NSAssert(_objectMapping, @"You must create objectMapping"); NSAssert(_objectMapping, @"You must create objectMapping");
_JSON = [[NSDictionary alloc] initWithDictionary:JSON]; _JSON = [[NSMutableDictionary alloc] initWithDictionary:JSON];
[self populateObjectFromJSON:JSON]; [self populateObjectFromJSON:JSON];
} }
return self; return self;
} }
- (BOOL)isStringNull:(NSString *)str - (NSDictionary * _Nonnull)reverseMapping
{
if(nil == str || NSNull.null == (id)str)
return YES;
else
return NO;
}
- (BOOL)isObjNull:(id)obj
{
if(nil == obj || NSNull.null == obj)
return YES;
else
return NO;
}
- (NSDictionary *)reverseMapping
{ {
NSMutableDictionary *JSON = [NSMutableDictionary dictionary]; NSMutableDictionary *JSON = [NSMutableDictionary dictionary];
@ -103,20 +100,66 @@
id value = [self valueForKey:propertyName]; id value = [self valueForKey:propertyName];
// NSDate NSLog(@"PropertyName PropertyType Value: %@ - %@ - %@",propertyName,propertyType,value);
if([propertyType isEqualToString:@"NSDate"]) {
((void (^)())@{
value = [NSDate stringFromDate:value]; @"c" : ^{
} char val = [value charValue];
// NSURL [JSON setValue:@(val) forKey:propertyName];
else if([propertyType isEqualToString:@"NSURL"]) { },
@"d" : ^{
double val = [value doubleValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"f" : ^{
float val = [value floatValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"i" : ^{
int val = [value intValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"l" : ^{
long val = [value longValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"s" : ^{
short val = [value shortValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"B" : ^{
BOOL val = [value boolValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"UIImage" : ^{
UIImage *image = [UIImage imageWithData:value];
[JSON setValue:image forKey:propertyName];
},
@"NSURL" : ^{
NSURL *url = value; NSURL *url = value;
value = [url absoluteString];
}
// NSArray, NSMutableArray
else if([propertyType isEqualToString:@"NSArray"] ||
[propertyType isEqualToString:@"NSMutableArray"]) {
if (![self isObjNull:url]) {
[JSON setValue:[url absoluteString] forKey:propertyName];
}
},
@"NSString" : ^{
NSString *val = [NSString stringWithFormat:@"%@", value];
if (![self isObjNull:val]) {
[JSON setValue:val forKey:propertyName];
}
},
@"NSNumber" : ^{
NSInteger val = [value integerValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"NSDate" : ^{
NSDate *val = [value toLocalTime];
if (![self isObjNull:val]) {
[JSON setValue:val forKey:propertyName];
}
},
@"NSArray" : ^{
NSMutableArray *arr = [NSMutableArray array]; NSMutableArray *arr = [NSMutableArray array];
for(id PNObject in value) { for(id PNObject in value) {
SEL selector = NSSelectorFromString(@"getObject"); SEL selector = NSSelectorFromString(@"getObject");
@ -130,13 +173,14 @@
[arr addObject:returnValue]; [arr addObject:returnValue];
} }
value = arr; [JSON setValue:arr forKey:propertyName];
},
} @"NSMutableArray" : ^{
// Other PNObject or an unidentified value NSMutableArray *arr = [NSMutableArray array];
else { for(id JSONObject in value) {
BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]]; PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject];
if(isPNObjectSubclass) { [arr addObject:val];
SEL selector = NSSelectorFromString(@"getObject"); SEL selector = NSSelectorFromString(@"getObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; [invocation setSelector:selector];
@ -144,17 +188,31 @@
[invocation invoke]; [invocation invoke];
NSDictionary *returnValue; NSDictionary *returnValue;
[invocation getReturnValue:&returnValue]; [invocation getReturnValue:&returnValue];
value = returnValue;
}
else {
// do nothing
} }
[JSON setValue:arr forKey:propertyName];
} }
}[propertyType] ?: ^{
BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
SEL selector = NSSelectorFromString(@"getObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:value];
[invocation invoke];
NSDictionary *returnValue;
[invocation getReturnValue:&returnValue];
[JSON setValue:returnValue forKey:propertyName];
}
else {
// do nothing
}
})();
[JSON setValue:value forKey:propertyName];
} }
_JSON = JSON; _JSON = JSON;
@ -162,121 +220,16 @@
return _JSON; return _JSON;
} }
- (NSDictionary*) getObject { - (NSDictionary* _Nonnull) getObject {
return [self reverseMapping]; return [self reverseMapping];
} }
- (void)populateObjectFromJSON:(id)JSON - (NSString* _Nonnull) description {
{ return [_JSON description];
NSDictionary *properties = [PNObjectProperty propertiesForClass:self.class];
for(NSString *propertyName in properties) {
if([propertyName isEqualToString:@"mappingError"])
continue;
NSString *mappedJSONKey;
NSString *mappedJSONType;
NSString *propertyType = [properties valueForKey:propertyName];
id mappingValue = [_objectMapping valueForKey:propertyName];
if([mappingValue isKindOfClass:NSDictionary.class]) {
mappedJSONKey = [mappingValue valueForKey:@"key"];
mappedJSONType = [mappingValue valueForKey:@"type"];
} else {
mappedJSONKey = mappingValue;
}
// Check if there is mapping for the property
if([self isStringNull:mappedJSONKey]) {
// No mapping so just continue
continue;
}
// Get JSON value for the mapped key
id value = [JSON valueForKeyPath:mappedJSONKey];
if([self isObjNull:value]) {
continue;
}
((void (^)())@{
@"c" : ^{
char val = [value charValue];
[self setValue:@(val) forKey:propertyName];
},
@"d" : ^{
double val = [value doubleValue];
[self setValue:@(val) forKey:propertyName];
},
@"f" : ^{
float val = [value floatValue];
[self setValue:@(val) forKey:propertyName];
},
@"i" : ^{
int val = [value intValue];
[self setValue:@(val) forKey:propertyName];
},
@"l" : ^{
long val = [value longValue];
[self setValue:@(val) forKey:propertyName];
},
@"s" : ^{
short val = [value shortValue];
[self setValue:@(val) forKey:propertyName];
},
@"NSString" : ^{
NSString *val = [NSString stringWithFormat:@"%@", value];
[self setValue:val forKey:propertyName];
},
@"NSNumber" : ^{
NSInteger val = [value integerValue];
[self setValue:@(val) forKey:propertyName];
},
@"NSDate" : ^{
NSString *str = [NSString stringWithFormat:@"%@", value];
NSDate *val = [[NSDate dateFromString:str withFormat:kNSDateHelperFormatSQLDateWithTime] toLocalTime];
[self setValue:val forKey:propertyName];
},
@"NSArray" : ^{
NSMutableArray *arr = [NSMutableArray array];
for(id JSONObject in value) {
PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject];
[arr addObject:val];
}
[self setValue:arr forKey:propertyName];
},
@"NSMutableArray" : ^{
NSMutableArray *arr = [NSMutableArray array];
for(id JSONObject in value) {
PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject];
[arr addObject:val];
}
[self setValue:arr forKey:propertyName];
}
}[propertyType] ?: ^{
BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
PNObject *val = [[NSClassFromString(propertyType) alloc] initWithJSON:value];
[self setValue:val forKey:propertyName];
}
else {
NSString *errorStr = [NSString stringWithFormat:@"Property '%@' could not be assigned any value.", propertyName];
NSLogDebug(@"%@",errorStr);
}
})();
}
} }
- (NSString*) description { - (void) setSingleInstance:(BOOL)singleInstance {
return [_JSON description]; _singleInstance = singleInstance;
} }
#pragma mark PNObjectPersistency protocol #pragma mark PNObjectPersistency protocol
@ -307,22 +260,7 @@
- (id _Nonnull) saveLocally { - (id _Nonnull) saveLocally {
if (_singleInstance) { return [_objectModel saveLocally:self];
return [_objectModel saveLocally:self];
}
else {
return [_objectModel pushObjectAndSaveLocally:self];
}
}
- (void) saveLocallyInBackGroundWithBlock:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock; {
if (_singleInstance) {
return [_objectModel saveLocally:self inBackGroundWithBlock:responseBlock];
}
else {
return [_objectModel pushObjectAndSaveLocally:self inBackGroundWithBlock:responseBlock];
}
} }
#pragma mark - #pragma mark -

View File

@ -32,14 +32,6 @@
*/ */
- (id _Nonnull) saveLocally:(id _Nonnull) object; - (id _Nonnull) saveLocally:(id _Nonnull) object;
/**
* <#Description#>
*
* @param object <#object description#>
* @param responseBlock <#responseBlock description#>
*/
- (void) saveLocally:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock;
/** /**
* <#Description#> * <#Description#>
* *
@ -47,14 +39,8 @@
* *
* @return <#return value description#> * @return <#return value description#>
*/ */
- (id _Nonnull) pushObjectAndSaveLocally:(id _Nonnull) object; - (id _Nonnull) removeObjectAndSaveLocally:(id _Nonnull) object;
/** - (id _Nonnull) fetchObjectsWithClass:(Class _Nonnull) class;
* <#Description#>
*
* @param object <#object description#>
* @param responseBlock <#responseBlock description#>
*/
- (void) pushObjectAndSaveLocally:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock;
@end @end

View File

@ -7,7 +7,7 @@
// //
#import "PNObjectModel.h" #import "PNObjectModel.h"
#import "PNObject.h" #import "PNObject+Protected.h"
#import "PEARFileManager.h" #import "PEARFileManager.h"
#import "PNObjectConstants.h" #import "PNObjectConstants.h"
@ -45,17 +45,19 @@ static bool isFirstAccess = YES;
if ([[object class] conformsToProtocol:@protocol(PNObjectSubclassing)]) { if ([[object class] conformsToProtocol:@protocol(PNObjectSubclassing)]) {
NSLogDebug(@"%@",[object subClassDelegate]); NSLogDebug(@"%@",[object subClassDelegate]);
NSString *className;
//if ([[object subClassDelegate] respondsToSelector:@selector(objectClassName)]) { //if ([[object subClassDelegate] respondsToSelector:@selector(objectClassName)]) {
@try { @try {
return (NSString *)[[object class] performSelector:@selector(objectClassName)];
className = (NSString *)[[object class] performSelector:@selector(objectClassName)];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
return nil; return nil;
} }
@finally { @finally {
return className;
} }
@ -121,6 +123,32 @@ static bool isFirstAccess = YES;
return self; return self;
} }
- (id _Nonnull) fetchObjectsWithClass:(Class _Nonnull) class {
BOOL isPNObjectSubclass = [class isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
NSString *className;
@try {
className = (NSString *)[class performSelector:@selector(objectClassName)];
}
@catch (NSException *exception) {
}
@finally {
if ([_fileManager checkPath:className]) {
return [NSKeyedUnarchiver unarchiveObjectWithData:[_fileManager fetchFileDataWithPath:className]];
}
else
return nil;
}
}
}
- (id _Nonnull) saveLocally:(id _Nonnull) object { - (id _Nonnull) saveLocally:(id _Nonnull) object {
@ -130,33 +158,95 @@ static bool isFirstAccess = YES;
if ([[object class] conformsToProtocol:@protocol(PNObjectSubclassing)]) { if ([[object class] conformsToProtocol:@protocol(PNObjectSubclassing)]) {
SEL selector = NSSelectorFromString(@"getObject"); if ([(PNObject*) object singleInstance]) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; SEL selector = NSSelectorFromString(@"getObject");
[invocation setTarget:object]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation invoke]; [invocation setSelector:selector];
[invocation setTarget:object];
NSDictionary *objectDict; [invocation invoke];
[invocation getReturnValue:&objectDict];
NSDictionary *objectDict;
NSLogDebug(@"%@",objectDict); [invocation getReturnValue:&objectDict];
NSData *objectData = [NSKeyedArchiver archivedDataWithRootObject:objectDict]; NSLogDebug(@"%@",objectDict);
if ([self issetPNObjectModelForObject:object]) { NSData *objectData = [NSKeyedArchiver archivedDataWithRootObject:objectDict];
if ([_fileManager updateFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) {
return object; if ([self issetPNObjectModelForObject:object]) {
if ([_fileManager updateFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) {
return object;
}
else {
return [NSError errorWithDomain:NSLocalizedString(@"Object cannot be updated", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
}
} }
else { else {
return [NSError errorWithDomain:NSLocalizedString(@"Object cannot be updated", @"") code:kHTTPStatusCodeBadRequest userInfo:nil]; if ([_fileManager createFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) {
return object;
}
else {
return [NSError errorWithDomain:NSLocalizedString(@"Object cannot be created", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
}
} }
} }
else { else {
if ([_fileManager createFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) { if ([self issetPNObjectModelForObject:object]) {
return object;
NSData * data = [_fileManager fetchFileDataWithPath:[self objectName:object]];
NSMutableArray *objects = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:data]];
SEL selector = NSSelectorFromString(@"getObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:object];
[invocation invoke];
NSDictionary *objectDict;
[invocation getReturnValue:&objectDict];
NSLogDebug(@"%@",objectDict);
[objects addObject:objectDict];
NSData *objectData = [NSKeyedArchiver archivedDataWithRootObject:objects];
if ([_fileManager updateFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) {
return objects;
}
else {
return [NSError errorWithDomain:NSLocalizedString(@"Objects list cannot be updated", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
}
} }
else { else {
return [NSError errorWithDomain:NSLocalizedString(@"Object cannot be created", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
NSMutableArray *objects = [[NSMutableArray alloc] init];
SEL selector = NSSelectorFromString(@"getObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:object];
[invocation invoke];
NSDictionary *objectDict;
[invocation getReturnValue:&objectDict];
NSLogDebug(@"%@",objectDict);
[objects addObject:objectDict];
NSData *objectData = [NSKeyedArchiver archivedDataWithRootObject:objects];
if ([_fileManager createFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) {
return object;
}
else {
return [NSError errorWithDomain:NSLocalizedString(@"Objects list cannot be created", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
}
} }
} }
} }
@ -169,31 +259,19 @@ static bool isFirstAccess = YES;
} }
} }
- (void) saveLocally:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock { - (id _Nonnull) removeObjectAndSaveLocally:(id _Nonnull) object {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
__weak id responseObject = [self saveLocally:object]; if ([[object class] conformsToProtocol:@protocol(PNObjectSubclassing)]) {
if ([responseObject isKindOfClass:[NSError class]]) {
if (responseBlock) { if ([(PNObject*) object singleInstance]) {
responseBlock(NO, nil, responseObject);
} }
} }
else if ([[responseObject class] isSubclassOfClass:[PNObject class]]){ }
if (responseBlock) {
responseBlock(YES,responseObject, nil);
}
}
});
}
- (id _Nonnull) pushObjectAndSaveLocally:(id _Nonnull) object {
}
- (void) pushObjectAndSaveLocally:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock {
} }
@end @end

View File

@ -7,6 +7,7 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "PNObject.h"
@interface PNObjectProperty : NSObject @interface PNObjectProperty : NSObject

View File

@ -9,6 +9,7 @@
#import "PNObjectProperty.h" #import "PNObjectProperty.h"
#import "objc/runtime.h" #import "objc/runtime.h"
#import "PNObjectConstants.h" #import "PNObjectConstants.h"
#import "PNObject+Protected.h"
@implementation PNObjectProperty @implementation PNObjectProperty
@ -38,6 +39,9 @@ static BOOL property_getTypeString( objc_property_t property, char *buffer )
} }
NSMutableDictionary *results = [NSMutableDictionary dictionary]; NSMutableDictionary *results = [NSMutableDictionary dictionary];
if ([PNObjClass isSubclassOfClass:[PNObject class]] && PNObjClass != [PNObject class]) {
[results addEntriesFromDictionary:[self propertiesForClass:[PNObject class]]];
}
unsigned int outCount, i; unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList(PNObjClass, &outCount); objc_property_t *properties = class_copyPropertyList(PNObjClass, &outCount);
@ -64,9 +68,11 @@ static BOOL property_getTypeString( objc_property_t property, char *buffer )
propertyType = [propertyType substringWithRange:subStrRange]; propertyType = [propertyType substringWithRange:subStrRange];
} }
NSLogDebug(@"Prop type & name: %@ -- %@", propertyType, propertyName); //NSLogDebug(@"Prop type & name: %@ -- %@", propertyType, propertyName);
[results setObject:propertyType forKey:propertyName]; if (![[PNObject protectedProperties] containsObject:propertyName]) {
[results setObject:propertyType forKey:propertyName];
}
} }
} }
free(properties); free(properties);

View File

@ -26,8 +26,7 @@
@property (nonatomic, strong) NSString * _Nonnull username; @property (nonatomic, strong) NSString * _Nonnull username;
@property (nonatomic, strong) NSString * _Nonnull password; @property (nonatomic, strong) NSString * _Nonnull password;
@property (nonatomic) BOOL publicProfile; @property (nonatomic) BOOL publicProfile;
@property (nonatomic) NSInteger loginCount; @property (nonatomic, strong) NSNumber * _Nonnull loginCount;
@property (strong, nonatomic) NSDate * _Nonnull createdAt;
@property (nonatomic, strong) NSString * _Nullable facebookId; @property (nonatomic, strong) NSString * _Nullable facebookId;
@property (nonatomic, strong) NSString * _Nullable facebookAccessToken; @property (nonatomic, strong) NSString * _Nullable facebookAccessToken;
@ -41,6 +40,6 @@
- (BOOL) isValidPassword:(NSString* _Nonnull) password; - (BOOL) isValidPassword:(NSString* _Nonnull) password;
- (void) setPassword:(NSString * _Nonnull)password withBlock:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock; //- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock;
@end @end

View File

@ -9,6 +9,7 @@
#import "PNUser.h" #import "PNUser.h"
#import "NSString+Helper.h" #import "NSString+Helper.h"
#import "PNObjectConstants.h" #import "PNObjectConstants.h"
#import "PNObject+Protected.h"
@interface PNUser() <PNObjectSubclassing> @interface PNUser() <PNObjectSubclassing>
@ -17,6 +18,8 @@
@implementation PNUser @implementation PNUser
@synthesize password = _password;
static PNUser *SINGLETON = nil; static PNUser *SINGLETON = nil;
static bool isFirstAccess = YES; static bool isFirstAccess = YES;
@ -25,17 +28,18 @@ static bool isFirstAccess = YES;
+ (instancetype)sharedInstance + (instancetype)sharedInstance
{ {
static dispatch_once_t onceToken; return [self currentUser];
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init];
});
return SINGLETON;
} }
+ (instancetype) currentUser { + (instancetype) currentUser {
return [self sharedInstance]; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init];
});
return SINGLETON;
} }
#pragma mark - Life Cycle #pragma mark - Life Cycle
@ -76,6 +80,12 @@ static bool isFirstAccess = YES;
self = [super init]; self = [super init];
if (self) { if (self) {
[self setSubClassDelegate:self]; [self setSubClassDelegate:self];
super.JSON = [super.objectModel fetchObjectsWithClass:[self class]];
if(super.JSON){
[super populateObjectFromJSON:super.JSON];
}
} }
return self; return self;
} }
@ -89,12 +99,13 @@ static bool isFirstAccess = YES;
- (void) setPassword:(NSString *)password { - (void) setPassword:(NSString *)password {
if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) { if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) {
self.password = password; _password = password;
}
else {
NSLogDebug(@"Inserted Passord is not valid.Lenght must be >= %ld",(long)[[PNObjectConfig sharedInstance] minPasswordLenght]);
} }
NSLogDebug(@"Inserted Passord is not valid.Lenght must be >= %ld",(long)[[PNObjectConfig sharedInstance] minPasswordLenght]);
} }
- (BOOL) isValidPassword:(NSString* _Nonnull) password { - (BOOL) isValidPassword:(NSString* _Nonnull) password {
if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) { if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) {
return YES; return YES;
@ -111,7 +122,8 @@ static bool isFirstAccess = YES;
+ (NSDictionary *)objcetMapping { + (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{@"userId":@"id", NSDictionary *mapping = @{
@"userId":@"id",
@"firstName":@"firstName", @"firstName":@"firstName",
@"lastName":@"lastName", @"lastName":@"lastName",
@"profileImage":@"profileImage", @"profileImage":@"profileImage",
@ -127,7 +139,6 @@ static bool isFirstAccess = YES;
@"username":@"username", @"username":@"username",
@"publicProfile":@"public_profile", @"publicProfile":@"public_profile",
@"loginCount":@"login_count", @"loginCount":@"login_count",
@"createdAt":@"created_at",
@"facebookId":@"facebookId", @"facebookId":@"facebookId",
@"facebookAccessToken":@"facebookAccessToken", @"facebookAccessToken":@"facebookAccessToken",
}; };