From c3e77e7a09cf2b0c43f4d0f68f85acdad495bcc8 Mon Sep 17 00:00:00 2001 From: Giuseppe Nucifora Date: Fri, 8 Jan 2016 20:21:22 +0100 Subject: [PATCH] - ADD PNObjectConfig Class - ADD PNObjectSubclassing Protocol --- Example/PNObject.xcodeproj/project.pbxproj | 13 +- .../xcschemes/PNObject-Example.xcscheme | 13 +- Example/PNObject/PNObject-Info.plist | 2 +- Example/PNObject/PNObjectAppDelegate.m | 5 + Example/PNObject/PNObjectViewController.m | 3 +- Example/Podfile | 2 +- Example/Podfile.lock | 2 +- Example/Pods/Manifest.lock | 2 +- Example/Pods/Pods.xcodeproj/project.pbxproj | 30 ++++ .../xcshareddata/xcschemes/PNObject.xcscheme | 2 +- .../ResourceBundle-NSDate_Utils-Info.plist | 4 +- .../ResourceBundle-PNObject-Info.plist | 4 +- .../ResourceBundle-UIDevice-Utils-Info.plist | 4 +- Example/Tests/Tests-Info.plist | 2 +- PNObject.podspec | 4 +- Pod/Classes/PNObject.h | 5 +- Pod/Classes/PNObject.m | 98 ++---------- Pod/Classes/PNObjectConfig.h | 47 ++++++ Pod/Classes/PNObjectConfig.m | 146 ++++++++++++++++++ Pod/Classes/PNObjectSubclassing.h | 20 +++ Pod/Classes/User/User.h | 13 ++ Pod/Classes/User/User.m | 22 +++ 22 files changed, 334 insertions(+), 109 deletions(-) create mode 100644 Pod/Classes/PNObjectConfig.h create mode 100644 Pod/Classes/PNObjectConfig.m create mode 100644 Pod/Classes/PNObjectSubclassing.h create mode 100644 Pod/Classes/User/User.h create mode 100644 Pod/Classes/User/User.m diff --git a/Example/PNObject.xcodeproj/project.pbxproj b/Example/PNObject.xcodeproj/project.pbxproj index 5f7f8b6..d649e20 100644 --- a/Example/PNObject.xcodeproj/project.pbxproj +++ b/Example/PNObject.xcodeproj/project.pbxproj @@ -246,7 +246,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = PNObject; - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0720; ORGANIZATIONNAME = "Giuseppe Nucifora"; TargetAttributes = { 6003F5AD195388D20070C39A = { @@ -454,6 +454,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -468,7 +469,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -501,7 +502,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -517,7 +518,9 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PNObject/PNObject-Prefix.pch"; INFOPLIST_FILE = "PNObject/PNObject-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MODULE_NAME = ExampleApp; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -532,7 +535,9 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PNObject/PNObject-Prefix.pch"; INFOPLIST_FILE = "PNObject/PNObject-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MODULE_NAME = ExampleApp; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -555,6 +560,7 @@ "$(inherited)", ); INFOPLIST_FILE = "Tests/Tests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PNObject_Example.app/PNObject_Example"; WRAPPER_EXTENSION = xctest; @@ -574,6 +580,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; INFOPLIST_FILE = "Tests/Tests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PNObject_Example.app/PNObject_Example"; WRAPPER_EXTENSION = xctest; diff --git a/Example/PNObject.xcodeproj/xcshareddata/xcschemes/PNObject-Example.xcscheme b/Example/PNObject.xcodeproj/xcshareddata/xcschemes/PNObject-Example.xcscheme index 4b4fa80..9861ec6 100644 --- a/Example/PNObject.xcodeproj/xcshareddata/xcschemes/PNObject-Example.xcscheme +++ b/Example/PNObject.xcodeproj/xcshareddata/xcschemes/PNObject-Example.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -48,15 +48,18 @@ ReferencedContainer = "container:PNObject.xcodeproj"> + + @@ -72,10 +75,10 @@ diff --git a/Example/PNObject/PNObject-Info.plist b/Example/PNObject/PNObject-Info.plist index d2cd320..b06b79c 100644 --- a/Example/PNObject/PNObject-Info.plist +++ b/Example/PNObject/PNObject-Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Example/PNObject/PNObjectAppDelegate.m b/Example/PNObject/PNObjectAppDelegate.m index e176809..f73013c 100644 --- a/Example/PNObject/PNObjectAppDelegate.m +++ b/Example/PNObject/PNObjectAppDelegate.m @@ -7,12 +7,17 @@ // #import "PNObjectAppDelegate.h" +#import "PNObject.h" @implementation PNObjectAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. + [PNObjectConfig sharedInstanceForEnvironments:@{ EnvironmentDevelopment : @"https://development.it/api/v1", + EnvironmentStage : @"https://stage.it/api/v1", + //EnvironmentProduction : @"https://production.it/api/v1" + }]; return YES; } diff --git a/Example/PNObject/PNObjectViewController.m b/Example/PNObject/PNObjectViewController.m index 079ef37..68743bc 100644 --- a/Example/PNObject/PNObjectViewController.m +++ b/Example/PNObject/PNObjectViewController.m @@ -9,6 +9,7 @@ #import "PNObjectViewController.h" //#import "PNObject.h" + @interface PNObjectViewController () @end @@ -18,7 +19,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. + // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning diff --git a/Example/Podfile b/Example/Podfile index eb2cad1..99cd358 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -8,7 +8,7 @@ target 'PNObject_Example' do pod 'PEAR-FileManager-iOS' pod 'NSDate_Utils' pod 'UIDevice-Utils' - pod 'AFNetworking' + pod 'AFNetworking', end target 'PNObject_Tests' do diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 095972a..bcbd240 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -57,4 +57,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 6a156edc70605054ee3ec9b0a6d6af416e100bf0 -COCOAPODS: 1.0.0.beta.1 +COCOAPODS: 1.0.0.beta.2 diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index 095972a..bcbd240 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -57,4 +57,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 6a156edc70605054ee3ec9b0a6d6af416e100bf0 -COCOAPODS: 1.0.0.beta.1 +COCOAPODS: 1.0.0.beta.2 diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 9484c3f..7615ec0 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -101,6 +101,12 @@ 66A27898E989A3FA5C15AA671C4536F0 /* EXPMatchers+beIdenticalTo.m in Sources */ = {isa = PBXBuildFile; fileRef = ABC2BD19C88FB68928A4ACDD68A9A724 /* EXPMatchers+beIdenticalTo.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 67459AD239EF669A365519E06B45DCFE /* EXPExpect.h in Headers */ = {isa = PBXBuildFile; fileRef = A9C30C86ADD90253F9625EE97E677992 /* EXPExpect.h */; settings = {ATTRIBUTES = (Public, ); }; }; 68152D921ABF6A423C192C04FDF94F0F /* AFNetworkReachabilityManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D147D9B92257C3B94B576C35DC424BF /* AFNetworkReachabilityManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6836B1401C40187C00FEFA54 /* User.h in Headers */ = {isa = PBXBuildFile; fileRef = 6836B13E1C40187C00FEFA54 /* User.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6836B1411C40187C00FEFA54 /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = 6836B13F1C40187C00FEFA54 /* User.m */; }; + 685036881C402C0F00202BC4 /* PNObjectSubclassing.h in Headers */ = {isa = PBXBuildFile; fileRef = 685036871C402C0F00202BC4 /* PNObjectSubclassing.h */; }; + 6850368C1C403F0D00202BC4 /* PNObjectSubclassing.h in Headers */ = {isa = PBXBuildFile; fileRef = 685036871C402C0F00202BC4 /* PNObjectSubclassing.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6850368D1C403F2C00202BC4 /* PNObjectConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 6850368A1C40331900202BC4 /* PNObjectConfig.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6850368E1C40418E00202BC4 /* PNObjectConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 6850368B1C40331900202BC4 /* PNObjectConfig.m */; }; 68A38977EBAE334DC3C22386D00D2622 /* AFNetworkReachabilityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 01C0656AD6CD15FA1E1CD0B12E72DBAC /* AFNetworkReachabilityManager.m */; }; 6B8F67BF9EF9C0D399893E9C92482D49 /* SpectaUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E49D273A400D01F7C968DEDB310739A /* SpectaUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6E1D978790705E137FDE439AA68DD3AA /* EXPFloatTuple.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F3C1DB6F4E00473063EACFC5515CC3 /* EXPFloatTuple.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -423,7 +429,12 @@ 64ABF623C50C215070FC44795D797682 /* EXPMatchers+beKindOf.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "EXPMatchers+beKindOf.m"; path = "Expecta/Matchers/EXPMatchers+beKindOf.m"; sourceTree = ""; }; 64F490A38FEF85969F7D32CF7DAD9297 /* SPTSpec.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SPTSpec.m; path = Specta/Specta/SPTSpec.m; sourceTree = ""; }; 680CFD1FCDFA6B058464345597F0BBF0 /* EXPUnsupportedObject.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = EXPUnsupportedObject.h; path = Expecta/EXPUnsupportedObject.h; sourceTree = ""; }; + 6836B13E1C40187C00FEFA54 /* User.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = User.h; sourceTree = ""; }; + 6836B13F1C40187C00FEFA54 /* User.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = User.m; sourceTree = ""; }; 684260D2513FE8AD036B49C00B805318 /* Expecta.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Expecta.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 685036871C402C0F00202BC4 /* PNObjectSubclassing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNObjectSubclassing.h; sourceTree = ""; }; + 6850368A1C40331900202BC4 /* PNObjectConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PNObjectConfig.h; sourceTree = ""; }; + 6850368B1C40331900202BC4 /* PNObjectConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PNObjectConfig.m; sourceTree = ""; }; 69C520A4C76B14DB186E153AEE415291 /* SpectaTypes.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SpectaTypes.h; path = Specta/Specta/SpectaTypes.h; sourceTree = ""; }; 6A9C98362B8CD1F0E2749529D53DEE66 /* AFURLRequestSerialization.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = AFURLRequestSerialization.h; path = AFNetworking/AFURLRequestSerialization.h; sourceTree = ""; }; 6BCF0B57CC5FE7DB7261CE7C60EAE6C1 /* NSDate_Utils.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NSDate_Utils.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -958,6 +969,15 @@ path = AFNetworking; sourceTree = ""; }; + 6836B13D1C40185A00FEFA54 /* User */ = { + isa = PBXGroup; + children = ( + 6836B13E1C40187C00FEFA54 /* User.h */, + 6836B13F1C40187C00FEFA54 /* User.m */, + ); + path = User; + sourceTree = ""; + }; 6963333AA224B56F4EA948D1389FFA46 /* UIDevice-Utils */ = { isa = PBXGroup; children = ( @@ -1121,10 +1141,14 @@ AE64835AD928C05A0E07671000DB2081 /* Classes */ = { isa = PBXGroup; children = ( + 6836B13D1C40185A00FEFA54 /* User */, E1E0780BB830EFAC797B401B279BC515 /* PNObject.h */, 941FEF92BBC85C24850889688C55A31A /* PNObject.m */, D0251859D2194B8DD130203343433439 /* PNObjectProperty.h */, 570E079E6A901F2AD57E8F3241BCE8C3 /* PNObjectProperty.m */, + 685036871C402C0F00202BC4 /* PNObjectSubclassing.h */, + 6850368A1C40331900202BC4 /* PNObjectConfig.h */, + 6850368B1C40331900202BC4 /* PNObjectConfig.m */, ); path = Classes; sourceTree = ""; @@ -1340,6 +1364,7 @@ 659960F7E28E993E08CCC1E8A383E710 /* UIKit+AFNetworking.h in Headers */, D9F4E833E37B611B432F6B5D7072DDA2 /* UIProgressView+AFNetworking.h in Headers */, C6354FEC7728A4C86DAD8092509BA7D4 /* UIRefreshControl+AFNetworking.h in Headers */, + 685036881C402C0F00202BC4 /* PNObjectSubclassing.h in Headers */, AE2A07407FB50BA249984DC0620E84C0 /* UIWebView+AFNetworking.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1406,6 +1431,9 @@ 003FC52F29E9B9B55FFC8C2C1E57D6BE /* PNObject-umbrella.h in Headers */, 98A194768324928F76BF544EEE5EDBE5 /* PNObject.h in Headers */, 410F22568A4D148214B412697A2322E6 /* PNObjectProperty.h in Headers */, + 6850368C1C403F0D00202BC4 /* PNObjectSubclassing.h in Headers */, + 6836B1401C40187C00FEFA54 /* User.h in Headers */, + 6850368D1C403F2C00202BC4 /* PNObjectConfig.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1825,9 +1853,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6836B1411C40187C00FEFA54 /* User.m in Sources */, 2FC59A81B07D43DCB4CAE4962F4A6018 /* PNObject-dummy.m in Sources */, 4E9495420371C304945421EA68F69B22 /* PNObject.m in Sources */, E1D01718CD5CFB570AE7B1D46BCE1436 /* PNObjectProperty.m in Sources */, + 6850368E1C40418E00202BC4 /* PNObjectConfig.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme index bd0dca9..fa66ac2 100644 --- a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme +++ b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme @@ -14,7 +14,7 @@ buildForArchiving = "YES"> diff --git a/Example/Pods/Target Support Files/NSDate_Utils/ResourceBundle-NSDate_Utils-Info.plist b/Example/Pods/Target Support Files/NSDate_Utils/ResourceBundle-NSDate_Utils-Info.plist index 161a9d3..aec6281 100644 --- a/Example/Pods/Target Support Files/NSDate_Utils/ResourceBundle-NSDate_Utils-Info.plist +++ b/Example/Pods/Target Support Files/NSDate_Utils/ResourceBundle-NSDate_Utils-Info.plist @@ -4,8 +4,6 @@ CFBundleDevelopmentRegion en - CFBundleExecutable - ${EXECUTABLE_NAME} CFBundleIdentifier ${PRODUCT_BUNDLE_IDENTIFIER} CFBundleInfoDictionaryVersion @@ -13,7 +11,7 @@ CFBundleName ${PRODUCT_NAME} CFBundlePackageType - FMWK + BNDL CFBundleShortVersionString 0.1.0 CFBundleSignature diff --git a/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist b/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist index 161a9d3..aec6281 100644 --- a/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist +++ b/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist @@ -4,8 +4,6 @@ CFBundleDevelopmentRegion en - CFBundleExecutable - ${EXECUTABLE_NAME} CFBundleIdentifier ${PRODUCT_BUNDLE_IDENTIFIER} CFBundleInfoDictionaryVersion @@ -13,7 +11,7 @@ CFBundleName ${PRODUCT_NAME} CFBundlePackageType - FMWK + BNDL CFBundleShortVersionString 0.1.0 CFBundleSignature diff --git a/Example/Pods/Target Support Files/UIDevice-Utils/ResourceBundle-UIDevice-Utils-Info.plist b/Example/Pods/Target Support Files/UIDevice-Utils/ResourceBundle-UIDevice-Utils-Info.plist index 7c241fa..5365749 100644 --- a/Example/Pods/Target Support Files/UIDevice-Utils/ResourceBundle-UIDevice-Utils-Info.plist +++ b/Example/Pods/Target Support Files/UIDevice-Utils/ResourceBundle-UIDevice-Utils-Info.plist @@ -4,8 +4,6 @@ CFBundleDevelopmentRegion en - CFBundleExecutable - ${EXECUTABLE_NAME} CFBundleIdentifier ${PRODUCT_BUNDLE_IDENTIFIER} CFBundleInfoDictionaryVersion @@ -13,7 +11,7 @@ CFBundleName ${PRODUCT_NAME} CFBundlePackageType - FMWK + BNDL CFBundleShortVersionString 0.1.2 CFBundleSignature diff --git a/Example/Tests/Tests-Info.plist b/Example/Tests/Tests-Info.plist index 41520ed..169b6f7 100644 --- a/Example/Tests/Tests-Info.plist +++ b/Example/Tests/Tests-Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType diff --git a/PNObject.podspec b/PNObject.podspec index 023d1b3..086d0a2 100644 --- a/PNObject.podspec +++ b/PNObject.podspec @@ -18,11 +18,11 @@ Pod::Spec.new do |s| # * Finally, don't worry about the indent, CocoaPods strips it! # s.description = <<-DESC DESC - s.homepage = "https://github.com//PNObject" + s.homepage = "https://github.com/giuseppenucifora/PNObject" # s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2" s.license = 'MIT' s.author = { "Giuseppe Nucifora" => "me@giuseppenucifora.com" } - s.source = { :git => "https://github.com//PNObject.git", :tag => s.version.to_s } + s.source = { :git => "https://github.com/giuseppenucifora/PNObject.git", :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/' s.platform = :ios, '7.0' diff --git a/Pod/Classes/PNObject.h b/Pod/Classes/PNObject.h index 2fd3d22..3b8fdbd 100644 --- a/Pod/Classes/PNObject.h +++ b/Pod/Classes/PNObject.h @@ -7,8 +7,10 @@ // #import +#import "PNObjectSubclassing.h" +#import "PNObjectConfig.h" -@interface PNObject : NSObject +@interface PNObject : NSObject @property (nonatomic, strong) NSString *objID; @property (nonatomic, strong) NSDate *createdDate; @@ -17,4 +19,5 @@ - (instancetype) initWithJSON:(NSDictionary*) JSON; + @end diff --git a/Pod/Classes/PNObject.m b/Pod/Classes/PNObject.m index f35f479..4f0f820 100644 --- a/Pod/Classes/PNObject.m +++ b/Pod/Classes/PNObject.m @@ -9,6 +9,7 @@ #import "PNObject.h" #import #import +#import @interface PNObject() @@ -24,8 +25,8 @@ self = [super init]; if (self) { - NSAssert(_objectMapping, @"You must create objectMapping"); - + + } return self; } @@ -33,6 +34,7 @@ - (instancetype) initWithJSON:(NSDictionary*) JSON { self = [self init]; if (self) { + NSAssert(_objectMapping, @"You must create objectMapping"); _JSON = [[NSDictionary alloc] initWithDictionary:JSON]; [self populateObjectFromJSON:JSON]; @@ -247,88 +249,20 @@ NSLog(@"%@",errorStr); } })(); - /*// char - if([propertyType isEqualToString:@"c"]) { - char val = [value charValue]; - [self setValue:@(val) forKey:propertyName]; - } - // double - else if([propertyType isEqualToString:@"d"]) { - double val = [value doubleValue]; - [self setValue:@(val) forKey:propertyName]; - } - // float - else if([propertyType isEqualToString:@"f"]) { - float val = [value floatValue]; - [self setValue:@(val) forKey:propertyName]; - } - // integer - else if([propertyType isEqualToString:@"i"]) { - int val = [value intValue]; - [self setValue:@(val) forKey:propertyName]; - } - // long - else if([propertyType isEqualToString:@"l"]) { - long val = [value longValue]; - [self setValue:@(val) forKey:propertyName]; - } - // short - else if([propertyType isEqualToString:@"s"]) { - short val = [value shortValue]; - [self setValue:@(val) forKey:propertyName]; - } - // NSString - else if([propertyType isEqualToString:@"NSString"]) { - NSString *val = [NSString stringWithFormat:@"%@", value]; - [self setValue:val forKey:propertyName]; - } - // NSNumber - else if([propertyType isEqualToString:@"NSNumber"]) { - NSInteger val = [value integerValue]; - [self setValue:@(val) forKey:propertyName]; - } - // NSDate - else if([propertyType isEqualToString:@"NSDate"]) { - - - NSString *str = [NSString stringWithFormat:@"%@", value]; - NSDate *val = [NSDate dateFromString:str]; - [self setValue:val forKey:propertyName]; - } - // NSURL - else if([propertyType isEqualToString:@"NSURL"]) { - NSString *str = [NSString stringWithFormat:@"%@", value]; - NSURL *val = [NSURL URLWithString:str]; - [self setValue:val forKey:propertyName]; - } - // NSArray, NSMutableArray - else if([propertyType isEqualToString:@"NSArray"] || - [propertyType isEqualToString:@"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]; - - } - // Other LLModel or an unidentified value - else { - 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]; - NSLog(@"%@",errorStr); - } - }*/ - } } +#pragma mark PNObjectSubclassing + ++ (NSString *) objectClassName { + +} + ++ (NSDictionary *) objcetMapping { + +} + +#pragma mark - + @end diff --git a/Pod/Classes/PNObjectConfig.h b/Pod/Classes/PNObjectConfig.h new file mode 100644 index 0000000..6d8631e --- /dev/null +++ b/Pod/Classes/PNObjectConfig.h @@ -0,0 +1,47 @@ +// +// PNObjectConfig.h +// Pods +// +// Created by Giuseppe Nucifora on 08/01/16. +// +// + +#import + +typedef NS_ENUM(NSInteger, Environment) { + Development, + Stage, + Production +}; + +extern NSString* const EnvironmentProduction; +extern NSString* const EnvironmentStage; +extern NSString* const EnvironmentDevelopment; + +@interface PNObjectConfig : NSObject + + + +/** + * gets singleton object. + * @return singleton + */ +/** + * + * + * @param clientIdsForEnvironments + * For example, + * @{ PNObjectConfigDevelopment : @"https://development.it/api/v1", + * PNObjectConfigEnvStage : @"ttps://stage.it/api/v1", + * PNObjectConfigEnvProduction : @"ttps://production.it/api/v1" + * } + * + * @return singleton + */ ++ (instancetype) sharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments; + +- (void) enableEnvironment:(Environment) env; + + + +@end \ No newline at end of file diff --git a/Pod/Classes/PNObjectConfig.m b/Pod/Classes/PNObjectConfig.m new file mode 100644 index 0000000..eed0706 --- /dev/null +++ b/Pod/Classes/PNObjectConfig.m @@ -0,0 +1,146 @@ +// +// PNObjectConfig.m +// Pods +// +// Created by Giuseppe Nucifora on 08/01/16. +// +// + +#import "PNObjectConfig.h" + +NSString* const EnvironmentProduction = @"PNObjectConfigEnvProduction"; +NSString* const EnvironmentStage = @"PNObjectConfigEnvStage"; +NSString* const EnvironmentDevelopment = @"PNObjectConfigDevelopment"; + + +@interface PNObjectConfig() + +@property (nonatomic, strong) NSMutableDictionary *configuration; +@property (nonatomic) BOOL devEnabled; +@property (nonatomic) BOOL stageEnabled; +@property (nonatomic) BOOL productionEnabled; + +@end + +@implementation PNObjectConfig + + + +static PNObjectConfig *SINGLETON = nil; + +static bool isFirstAccess = YES; + +#pragma mark - Public Method + ++ (id)sharedInstance +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + isFirstAccess = NO; + SINGLETON = [[super allocWithZone:NULL] init]; + }); + + return SINGLETON; +} + +#pragma mark - Life Cycle + ++ (instancetype) sharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments { + SINGLETON = [self sharedInstance]; + + if (SINGLETON) { + for (NSString *key in [endpointUrlsForEnvironments allKeys]) { + + ((void (^)())@{ + EnvironmentDevelopment : ^{ + NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; + if (endpointUrl) { + [SINGLETON.configuration setValue:endpointUrl forKey:key]; + SINGLETON.devEnabled = YES; + } + + }, + EnvironmentStage : ^{ + NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; + if (endpointUrl) { + [SINGLETON.configuration setValue:endpointUrl forKey:key]; + SINGLETON.stageEnabled = YES; + } + }, + EnvironmentProduction : ^{ + NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; + if (endpointUrl) { + [SINGLETON.configuration setValue:endpointUrl forKey:key]; + SINGLETON.productionEnabled = YES; + } + } + }[key] ?: ^{ + + })(); + } + NSAssert(SINGLETON.productionEnabled, @"EnvironmentProduction must be valid endpoint url"); + + NSLog(@"Config : %@",SINGLETON.configuration); + } + return SINGLETON; +} + ++ (id) allocWithZone:(NSZone *)zone +{ + return [self sharedInstance]; +} + ++ (id)copyWithZone:(struct _NSZone *)zone +{ + return [self sharedInstance]; +} + ++ (id)mutableCopyWithZone:(struct _NSZone *)zone +{ + return [self sharedInstance]; +} + +- (id)copy +{ + return [[PNObjectConfig alloc] init]; +} + +- (id)mutableCopy +{ + return [[PNObjectConfig alloc] init]; +} + +- (id) init +{ + if(SINGLETON){ + return SINGLETON; + } + if (isFirstAccess) { + [self doesNotRecognizeSelector:_cmd]; + } + self = [super init]; + + if (self) { + _configuration = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (void) enableEnvironment:(Environment) env { + + switch (env) { + case Development:{ + + } + break; + case Stage:{ + + } + break; + case Production: + default: + break; + } +} + +@end diff --git a/Pod/Classes/PNObjectSubclassing.h b/Pod/Classes/PNObjectSubclassing.h new file mode 100644 index 0000000..5e3a7c5 --- /dev/null +++ b/Pod/Classes/PNObjectSubclassing.h @@ -0,0 +1,20 @@ +// +// PNObjectSubclassing.h +// Pods +// +// Created by Giuseppe Nucifora on 08/01/16. +// +// + +#import +#import + +@protocol PNObjectSubclassing + +@required + ++ (NSString *) objectClassName; + ++ (NSDictionary *) objcetMapping; + +@end diff --git a/Pod/Classes/User/User.h b/Pod/Classes/User/User.h new file mode 100644 index 0000000..0727b8e --- /dev/null +++ b/Pod/Classes/User/User.h @@ -0,0 +1,13 @@ +// +// User.h +// Pods +// +// Created by Giuseppe Nucifora on 08/01/16. +// +// + +#import + +@interface User : PNObject + +@end diff --git a/Pod/Classes/User/User.m b/Pod/Classes/User/User.m new file mode 100644 index 0000000..9d54ee7 --- /dev/null +++ b/Pod/Classes/User/User.m @@ -0,0 +1,22 @@ +// +// User.m +// Pods +// +// Created by Giuseppe Nucifora on 08/01/16. +// +// + +#import "User.h" + +@implementation User + +- (instancetype) initWithJSON:(NSDictionary *)JSON { + + self = [super initWithJSON:JSON]; + if (self) { + + } + return self; +} + +@end