diff --git a/QuickDialog.xcodeproj/project.pbxproj b/QuickDialog.xcodeproj/project.pbxproj index 072ea2ee..3438b733 100644 --- a/QuickDialog.xcodeproj/project.pbxproj +++ b/QuickDialog.xcodeproj/project.pbxproj @@ -109,6 +109,8 @@ D8F180E813F0599A009B0CB1 /* jsonadvancedsample.json in Resources */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CB0 /* jsonadvancedsample.json */; }; D8F180E813F0599A009B0CB3 /* BindingEvaluator.m in Sources */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CB2 /* BindingEvaluator.m */; }; D8F180E813F0599A009B0CB5 /* BindingEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CB4 /* BindingEvaluator.h */; }; + D8F180E813F0599A009B0CB7 /* QRootBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CB6 /* QRootBuilder.m */; }; + D8F180E813F0599A009B0CB9 /* QRootBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CB8 /* QRootBuilder.h */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -235,6 +237,8 @@ D8F180E813F0599A009B0CB0 /* jsonadvancedsample.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = jsonadvancedsample.json; sourceTree = ""; }; D8F180E813F0599A009B0CB2 /* BindingEvaluator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BindingEvaluator.m; path = quickdialog/BindingEvaluator.m; sourceTree = SOURCE_ROOT; }; D8F180E813F0599A009B0CB4 /* BindingEvaluator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BindingEvaluator.h; path = quickdialog/BindingEvaluator.h; sourceTree = SOURCE_ROOT; }; + D8F180E813F0599A009B0CB6 /* QRootBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QRootBuilder.m; path = quickdialog/QRootBuilder.m; sourceTree = SOURCE_ROOT; }; + D8F180E813F0599A009B0CB8 /* QRootBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QRootBuilder.h; path = quickdialog/QRootBuilder.h; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -374,6 +378,8 @@ D860356713E0534000CB1785 /* quickdialog */ = { isa = PBXGroup; children = ( + D8F180E813F0599A009B0CB8 /* QRootBuilder.h */, + D8F180E813F0599A009B0CB6 /* QRootBuilder.m */, D8F180E813F0599A009B0CB4 /* BindingEvaluator.h */, D8F180E813F0599A009B0CB2 /* BindingEvaluator.m */, D8F180E813F0599A009B0CA9 /* QBadgeLabel.h */, @@ -494,6 +500,7 @@ D8F180E813F0599A009B0CAA /* QBadgeLabel.h in Headers */, D8F180E813F0599A009B0CB5 /* BindingEvaluator.h in Headers */, D871018614BB3D7A00156D9D /* QRootElement+Builder.h in Headers */, + D8F180E813F0599A009B0CB9 /* QRootBuilder.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -626,6 +633,7 @@ D8F180E813F0599A009B0CA8 /* QBadgeLabel.m in Sources */, D8F180E813F0599A009B0CB3 /* BindingEvaluator.m in Sources */, D871018714BB3D7A00156D9D /* QRootElement+Builder.m in Sources */, + D8F180E813F0599A009B0CB7 /* QRootBuilder.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/quickdialog/BindingEvaluator.h b/quickdialog/BindingEvaluator.h index 8c10cc32..2e7e2219 100644 --- a/quickdialog/BindingEvaluator.h +++ b/quickdialog/BindingEvaluator.h @@ -1,7 +1,18 @@ // -// Created by escoz on 1/8/12. +// Copyright 2011 ESCOZ Inc - http://escoz.com +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. // + #import @@ -13,4 +24,5 @@ - (void)bindSection:(QSection *)section toCollection:(NSArray *)items; - (void)bindSection:(QSection *)section toProperties:(id)object; + @end \ No newline at end of file diff --git a/quickdialog/BindingEvaluator.m b/quickdialog/BindingEvaluator.m index fa9f4fc1..e0d4188d 100644 --- a/quickdialog/BindingEvaluator.m +++ b/quickdialog/BindingEvaluator.m @@ -1,6 +1,17 @@ // -// Created by escoz on 1/8/12. +// Copyright 2011 ESCOZ Inc - http://escoz.com // +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + #import "BindingEvaluator.h" @interface BindingEvaluator () @@ -8,7 +19,17 @@ + (BOOL)stringIsEmpty:(NSString *)aString; @end -@implementation BindingEvaluator +@implementation BindingEvaluator { + QRootBuilder *_builder; +} +- (id)init { + self = [super init]; + if (self) { + _builder = [QRootBuilder new]; + } + + return self; +} - (void)bindObject:(id)object toData:(id)data { if (![object respondsToSelector:@selector(bind)]) @@ -20,6 +41,7 @@ - (void)bindObject:(id)object toData:(id)data { for (NSString *each in [string componentsSeparatedByString:@","]) { NSArray *bindingParams = [each componentsSeparatedByString:@":"]; + NSString *propName = [((NSString *) [bindingParams objectAtIndex:0]) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSString *valueName = [((NSString *) [bindingParams objectAtIndex:1]) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; @@ -30,8 +52,7 @@ - (void)bindObject:(id)object toData:(id)data { [self bindSection:(QSection *)object toProperties:[data objectForKey:valueName]]; } else if ([data objectForKey:valueName]!=nil) { - [object setValue:[data objectForKey:valueName] forKey:propName]; - + [QRootBuilder trySetProperty:propName onObject:object withValue:[data objectForKey:valueName]]; } } } @@ -50,8 +71,9 @@ + (BOOL)stringIsEmpty:(NSString *) aString { - (void)bindSection:(QSection *)section toCollection:(NSArray *)items { [section.elements removeAllObjects]; + for (id item in items){ - QElement *element = [section.rootElement buildElementWithObject:section.template]; + QElement *element = [_builder buildElementWithObject:section.template]; [section addElement:element]; [element bindToObject:item]; } @@ -60,8 +82,9 @@ - (void)bindSection:(QSection *)section toCollection:(NSArray *)items { - (void)bindSection:(QSection *)section toProperties:(NSDictionary *)object { [section.elements removeAllObjects]; for (id item in [object allKeys]){ - QElement *element = [section.rootElement buildElementWithObject:section.template]; + QElement *element = [_builder buildElementWithObject:section.template]; [section addElement:element]; + [element bindToObject:[NSDictionary dictionaryWithObjectsAndKeys:item, @"key", [object valueForKey:item], @"value", nil]]; } } diff --git a/quickdialog/QBadgeLabel.h b/quickdialog/QBadgeLabel.h index 201dc73e..5a293b97 100644 --- a/quickdialog/QBadgeLabel.h +++ b/quickdialog/QBadgeLabel.h @@ -1,6 +1,17 @@ // -// Created by escoz on 1/6/12. +// Copyright 2011 ESCOZ Inc - http://escoz.com // +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + #import diff --git a/quickdialog/QBadgeLabel.m b/quickdialog/QBadgeLabel.m index f43ed20b..2f68d503 100644 --- a/quickdialog/QBadgeLabel.m +++ b/quickdialog/QBadgeLabel.m @@ -1,7 +1,17 @@ // -// Created by escoz on 1/6/12. +// Copyright 2011 ESCOZ Inc - http://escoz.com // -#import "QBadgeLabel.h" +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + @implementation QBadgeLabel { UIColor *_badgeColor; diff --git a/quickdialog/QLabelElement.h b/quickdialog/QLabelElement.h index c4e6824c..051979e4 100644 --- a/quickdialog/QLabelElement.h +++ b/quickdialog/QLabelElement.h @@ -20,13 +20,13 @@ @interface QLabelElement : QRootElement { @protected - NSString *_value; + id _value; UIImage *_image; } @property(nonatomic, strong) UIImage *image; -@property(nonatomic, strong) NSString *value; +@property(nonatomic, strong) id value; -- (QLabelElement *)initWithTitle:(NSString *)string Value:(NSString *)value; +- (QLabelElement *)initWithTitle:(NSString *)string Value:(id)value; @end \ No newline at end of file diff --git a/quickdialog/QLabelElement.m b/quickdialog/QLabelElement.m index a8391132..4380e92f 100644 --- a/quickdialog/QLabelElement.m +++ b/quickdialog/QLabelElement.m @@ -20,7 +20,7 @@ @implementation QLabelElement @synthesize image = _image; @synthesize value = _value; -- (QLabelElement *)initWithTitle:(NSString *)title Value:(NSString *)value { +- (QLabelElement *)initWithTitle:(NSString *)title Value:(id)value { self = [super init]; _title = title; _value = value; @@ -33,7 +33,7 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.textLabel.text = _title; - cell.detailTextLabel.text = _value; + cell.detailTextLabel.text = [_value description]; cell.imageView.image = _image; cell.accessoryType = self.sections!= nil || self.controllerAction!=nil ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone; cell.selectionStyle = self.sections!= nil || self.controllerAction!=nil ? UITableViewCellSelectionStyleBlue: UITableViewCellSelectionStyleNone; diff --git a/quickdialog/QRootBuilder.h b/quickdialog/QRootBuilder.h new file mode 100644 index 00000000..3db02b7b --- /dev/null +++ b/quickdialog/QRootBuilder.h @@ -0,0 +1,29 @@ +// +// Copyright 2011 ESCOZ Inc - http://escoz.com +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + +#import +#import "quickdialog.h" + +@interface QRootBuilder : NSObject { + +} + +- (QRootElement *)buildSectionsWithObject:(id)obj; + ++ (void)trySetProperty:(NSString *)propertyName onObject:(id)target withValue:(id)value; + +- (QElement *)buildElementWithObject:(id)obj; + + +@end \ No newline at end of file diff --git a/quickdialog/QRootBuilder.m b/quickdialog/QRootBuilder.m new file mode 100644 index 00000000..9708c244 --- /dev/null +++ b/quickdialog/QRootBuilder.m @@ -0,0 +1,132 @@ +// +// Copyright 2011 ESCOZ Inc - http://escoz.com +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + +NSDictionary * QRootElementJSONBuilderConversionDict; + +@interface QRootBuilder () +- (void)initializeMappings; + +@end + +@implementation QRootBuilder + ++ (void)trySetProperty:(NSString *)propertyName onObject:(id)target withValue:(id)value { + if ([value isKindOfClass:[NSString class]] && [target respondsToSelector:NSSelectorFromString(propertyName)]) { + [target setValue:value forKey:propertyName]; + if ([QRootElementJSONBuilderConversionDict objectForKey:propertyName]!=nil) { + [target setValue:[[QRootElementJSONBuilderConversionDict objectForKey:propertyName] objectForKey:value] forKey:propertyName]; + } + } else if ([value isKindOfClass:[NSNumber class]]){ + [target setValue:value forKey:propertyName]; + } else if ([value isKindOfClass:[NSArray class]]) { + [target setValue:value forKey:propertyName]; + } else if ([value isKindOfClass:[NSDictionary class]]){ + [target setValue:value forKey:propertyName]; + } +} + +- (void)updateObject:(id)element withPropertiesFrom:(NSDictionary *)dict { + for (NSString *key in dict.allKeys){ + if ([key isEqualToString:@"type"] || [key isEqualToString:@"sections"]|| [key isEqualToString:@"elements"]) + continue; + + id value = [dict valueForKey:key]; + [QRootBuilder trySetProperty:key onObject:element withValue:value]; + } +} + +- (QElement *)buildElementWithObject:(id)obj { + QElement *element = [[NSClassFromString([obj valueForKey:[NSString stringWithFormat:@"type"]]) alloc] init]; + if (element==nil) + return nil; + [self updateObject:element withPropertiesFrom:obj]; + return element; +} + +- (void)buildSectionWithObject:(id)obj forRoot:(QRootElement *)root { + QSection *sect = [[QSection alloc] init]; + [self updateObject:sect withPropertiesFrom:obj]; + [root addSection:sect]; + for (id element in (NSArray *)[obj valueForKey:[NSString stringWithFormat:@"elements"]]){ + [sect addElement:[self buildElementWithObject:element] ]; + } +} + +- (QRootElement *)buildSectionsWithObject:(id)obj { + if (QRootElementJSONBuilderConversionDict==nil) + [self initializeMappings]; + + QRootElement *root = [QRootElement new]; + [self updateObject:root withPropertiesFrom:obj]; + for (id section in (NSArray *)[obj valueForKey:[NSString stringWithFormat:@"sections"]]){ + [self buildSectionWithObject:section forRoot:root]; + } + + return root; +} + +- (void)initializeMappings { + QRootElementJSONBuilderConversionDict = [[NSDictionary alloc] initWithObjectsAndKeys: + + [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:UITextAutocapitalizationTypeNone], @"None", + [NSNumber numberWithInt:UITextAutocapitalizationTypeWords], @"Words", + [NSNumber numberWithInt:UITextAutocapitalizationTypeSentences], @"Sentences", + [NSNumber numberWithInt:UITextAutocapitalizationTypeAllCharacters], @"AllCharacters", + nil], @"autocapitalizationType", + + [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:UITextAutocorrectionTypeDefault], @"Default", + [NSNumber numberWithInt:UITextAutocorrectionTypeNo], @"No", + [NSNumber numberWithInt:UITextAutocorrectionTypeYes], @"Yes", + nil], @"autocorrectionType", + + [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:UIKeyboardTypeDefault], @"Default", + [NSNumber numberWithInt:UIKeyboardTypeASCIICapable], @"ASCIICapable", + [NSNumber numberWithInt:UIKeyboardTypeNumbersAndPunctuation], @"NumbersAndPunctuation", + [NSNumber numberWithInt:UIKeyboardTypeURL], @"URL", + [NSNumber numberWithInt:UIKeyboardTypeNumberPad], @"NumberPad", + [NSNumber numberWithInt:UIKeyboardTypePhonePad], @"PhonePad", + [NSNumber numberWithInt:UIKeyboardTypeNamePhonePad], @"NamePhonePad", + [NSNumber numberWithInt:UIKeyboardTypeEmailAddress], @"EmailAddress", + [NSNumber numberWithInt:UIKeyboardTypeDecimalPad], @"DecimalPad", + [NSNumber numberWithInt:UIKeyboardTypeTwitter], @"Twitter", + [NSNumber numberWithInt:UIKeyboardTypeAlphabet], @"Alphabet", + nil], @"keyboardType", + + [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:UIKeyboardAppearanceDefault], @"Default", + [NSNumber numberWithInt:UIKeyboardAppearanceAlert], @"Alert", + nil], @"keyboardAppearance", + + [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:UIReturnKeyDefault], @"Default", + [NSNumber numberWithInt:UIReturnKeyGo], @"Go", + [NSNumber numberWithInt:UIReturnKeyGoogle], @"Google", + [NSNumber numberWithInt:UIReturnKeyJoin], @"Join", + [NSNumber numberWithInt:UIReturnKeyNext], @"Next", + [NSNumber numberWithInt:UIReturnKeyRoute], @"Route", + [NSNumber numberWithInt:UIReturnKeySearch], @"Search", + [NSNumber numberWithInt:UIReturnKeySend], @"Send", + [NSNumber numberWithInt:UIReturnKeyYahoo], @"Yahoo", + [NSNumber numberWithInt:UIReturnKeyDone], @"Done", + [NSNumber numberWithInt:UIReturnKeyEmergencyCall], @"EmergencyCall", + nil], @"returnKeyType", + + nil]; +} + + +@end \ No newline at end of file diff --git a/quickdialog/QRootElement+Builder.h b/quickdialog/QRootElement+Builder.h index 9de91e63..eff135fc 100644 --- a/quickdialog/QRootElement+Builder.h +++ b/quickdialog/QRootElement+Builder.h @@ -1,6 +1,17 @@ // -// Created by escoz on 11/1/11. +// Copyright 2011 ESCOZ Inc - http://escoz.com // +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + #import #import "QRootElement.h" @@ -8,11 +19,6 @@ @interface QRootElement (JSONBuilder) - (id)initWithJSONFile:(NSString *)json andData:(id)data; - -- (QElement *)buildElementWithObject:(id)obj; - - (id)initWithJSONFile:(NSString *)jsonPath; -+ (BOOL)jsonAvailable; - @end \ No newline at end of file diff --git a/quickdialog/QRootElement+Builder.m b/quickdialog/QRootElement+Builder.m index 97791d27..7c970ca7 100644 --- a/quickdialog/QRootElement+Builder.m +++ b/quickdialog/QRootElement+Builder.m @@ -1,62 +1,23 @@ // -// Created by escoz on 11/1/11. +// Copyright 2011 ESCOZ Inc - http://escoz.com +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. // -#import - -NSDictionary * QRootElementJSONBuilderConversionDict; - -@interface QRootElement () -- (void)initializeMappings; -@end +#import +#import "QRootBuilder.h" @implementation QRootElement (JSONBuilder) -- (void)updateObject:(id)element withPropertiesFrom:(NSDictionary *)dict { - for (NSString *key in dict.allKeys){ - if ([key isEqualToString:@"type"] || [key isEqualToString:@"sections"]|| [key isEqualToString:@"elements"]) - continue; - - id value = [dict valueForKey:key]; - if ([value isKindOfClass:[NSString class]] && [element respondsToSelector:NSSelectorFromString(key)]) { - [element setValue:value forKey:key]; - if ([QRootElementJSONBuilderConversionDict objectForKey:key]!=nil) { - [element setValue:[[QRootElementJSONBuilderConversionDict objectForKey:key] objectForKey:value] forKey:key]; - } - } else if ([value isKindOfClass:[NSNumber class]]){ - [element setValue:value forKey:key]; - } else if ([value isKindOfClass:[NSArray class]]) { - [element setValue:value forKey:key]; - } else if ([value isKindOfClass:[NSDictionary class]]){ - [element setValue:value forKey:key]; - } - } -} - -- (QElement *)buildElementWithObject:(id)obj { - QElement *element = [[NSClassFromString([obj valueForKey:[NSString stringWithFormat:@"type"]]) alloc] init]; - if (element==nil) - return nil; - [self updateObject:element withPropertiesFrom:obj]; - return element; -} - -- (void)buildSectionWithObject:(id)obj { - QSection *sect = [[QSection alloc] init]; - [self updateObject:sect withPropertiesFrom:obj]; - [self addSection:sect]; - for (id element in (NSArray *)[obj valueForKey:[NSString stringWithFormat:@"elements"]]){ - [sect addElement:[self buildElementWithObject:element] ]; - } -} - -- (void)buildSectionsWithObject:(id)obj { - [self updateObject:self withPropertiesFrom:obj]; - for (id section in (NSArray *)[obj valueForKey:[NSString stringWithFormat:@"sections"]]){ - [self buildSectionWithObject:section]; - } -} - (id)initWithJSONFile:(NSString *)jsonPath { self = [self initWithJSONFile:jsonPath andData:nil]; @@ -64,81 +25,18 @@ - (id)initWithJSONFile:(NSString *)jsonPath { } - (id)initWithJSONFile:(NSString *)jsonPath andData:(id)data { - self = [super init]; - Class JSONSerialization = objc_getClass("NSJSONSerialization"); NSAssert(JSONSerialization != NULL, @"No JSON serializer available!"); - - if (self!=nil){ - if (QRootElementJSONBuilderConversionDict==nil) - [self initializeMappings]; - - NSError *jsonParsingError = nil; - NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonPath ofType:@"json"]; - NSDictionary *jsonRoot = [JSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:filePath] options:0 error:&jsonParsingError]; - - [self buildSectionsWithObject:jsonRoot]; - if (data!=nil) - [self bindToObject:data]; - } - return self; -} - -+ (BOOL)jsonAvailable { - return objc_getClass("NSJSONSerialization") != NULL; -} -- (void)initializeMappings { - QRootElementJSONBuilderConversionDict = [[NSDictionary alloc] initWithObjectsAndKeys: + NSError *jsonParsingError = nil; + NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonPath ofType:@"json"]; + NSDictionary *jsonRoot = [JSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:filePath] options:0 error:&jsonParsingError]; - [[NSDictionary alloc] initWithObjectsAndKeys: - [NSNumber numberWithInt:UITextAutocapitalizationTypeNone], @"None", - [NSNumber numberWithInt:UITextAutocapitalizationTypeWords], @"Words", - [NSNumber numberWithInt:UITextAutocapitalizationTypeSentences], @"Sentences", - [NSNumber numberWithInt:UITextAutocapitalizationTypeAllCharacters], @"AllCharacters", - nil], @"autocapitalizationType", + self = [[QRootBuilder new] buildSectionsWithObject:jsonRoot]; + if (data!=nil) + [self bindToObject:data]; - [[NSDictionary alloc] initWithObjectsAndKeys: - [NSNumber numberWithInt:UITextAutocorrectionTypeDefault], @"Default", - [NSNumber numberWithInt:UITextAutocorrectionTypeNo], @"No", - [NSNumber numberWithInt:UITextAutocorrectionTypeYes], @"Yes", - nil], @"autocorrectionType", - - [[NSDictionary alloc] initWithObjectsAndKeys: - [NSNumber numberWithInt:UIKeyboardTypeDefault], @"Default", - [NSNumber numberWithInt:UIKeyboardTypeASCIICapable], @"ASCIICapable", - [NSNumber numberWithInt:UIKeyboardTypeNumbersAndPunctuation], @"NumbersAndPunctuation", - [NSNumber numberWithInt:UIKeyboardTypeURL], @"URL", - [NSNumber numberWithInt:UIKeyboardTypeNumberPad], @"NumberPad", - [NSNumber numberWithInt:UIKeyboardTypePhonePad], @"PhonePad", - [NSNumber numberWithInt:UIKeyboardTypeNamePhonePad], @"NamePhonePad", - [NSNumber numberWithInt:UIKeyboardTypeEmailAddress], @"EmailAddress", - [NSNumber numberWithInt:UIKeyboardTypeDecimalPad], @"DecimalPad", - [NSNumber numberWithInt:UIKeyboardTypeTwitter], @"Twitter", - [NSNumber numberWithInt:UIKeyboardTypeAlphabet], @"Alphabet", - nil], @"keyboardType", - - [[NSDictionary alloc] initWithObjectsAndKeys: - [NSNumber numberWithInt:UIKeyboardAppearanceDefault], @"Default", - [NSNumber numberWithInt:UIKeyboardAppearanceAlert], @"Alert", - nil], @"keyboardAppearance", - - [[NSDictionary alloc] initWithObjectsAndKeys: - [NSNumber numberWithInt:UIReturnKeyDefault], @"Default", - [NSNumber numberWithInt:UIReturnKeyGo], @"Go", - [NSNumber numberWithInt:UIReturnKeyGoogle], @"Google", - [NSNumber numberWithInt:UIReturnKeyJoin], @"Join", - [NSNumber numberWithInt:UIReturnKeyNext], @"Next", - [NSNumber numberWithInt:UIReturnKeyRoute], @"Route", - [NSNumber numberWithInt:UIReturnKeySearch], @"Search", - [NSNumber numberWithInt:UIReturnKeySend], @"Send", - [NSNumber numberWithInt:UIReturnKeyYahoo], @"Yahoo", - [NSNumber numberWithInt:UIReturnKeyDone], @"Done", - [NSNumber numberWithInt:UIReturnKeyEmergencyCall], @"EmergencyCall", - nil], @"returnKeyType", - - nil]; + return self; } - @end \ No newline at end of file diff --git a/quickdialog/QuickDialog.h b/quickdialog/QuickDialog.h index 0e227ceb..419d728d 100644 --- a/quickdialog/QuickDialog.h +++ b/quickdialog/QuickDialog.h @@ -35,4 +35,6 @@ #import "QSortingSection.h" #import "QDateTimeElement.h" #import "QWebViewController.h" -#import "QBadgeLabel.h" \ No newline at end of file +#import "QBadgeLabel.h" + +#import "QRootBuilder.h" \ No newline at end of file diff --git a/sample/SampleDataBuilder.m b/sample/SampleDataBuilder.m index 688cfd58..476c5020 100644 --- a/sample/SampleDataBuilder.m +++ b/sample/SampleDataBuilder.m @@ -13,6 +13,7 @@ // #import +#import #import "LoginController.h" #import "SampleDataBuilder.h" #import "QRootElement.h" @@ -501,7 +502,7 @@ + (QRootElement *)create { [root addSection:sectionSamples]; [root addSection:sectionElements]; - if ([QRootElement jsonAvailable]) { + if (objc_getClass("NSJSONSerialization")!=nil) { QSection *sectionJson = [[QSection alloc] initWithTitle:@"JSON Samples"]; [sectionJson addElement:[[QRootElement alloc] initWithJSONFile:@"loginform"]]; [sectionJson addElement:[[QRootElement alloc] initWithJSONFile:@"sample"]];