Last active
January 12, 2016 08:45
-
-
Save planetexpress69/380d7650b2c90aeda9f0 to your computer and use it in GitHub Desktop.
Product parsing for a certain project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidAppear:(BOOL)animated | |
{ | |
[super viewDidAppear:animated]; | |
CGRect viewFrame = self.view.frame; | |
viewFrame.size.height -= 90; // uistatusbar + navigationbar + title bar! | |
viewFrame.origin.y = 44; | |
self.tableView.frame = viewFrame; | |
self.foo = [NSMutableArray new]; | |
NSMutableDictionary *dItemPicture = [[self dExtract:@"product_pic" type:@"contentPlain"] mutableCopy]; | |
if (dItemPicture) { | |
[dItemPicture setObject:@"__Itempicture" forKey:@"headline"]; | |
[self.foo addObject:dItemPicture]; // Picture | |
} else { | |
[self.foo addObject:@{ | |
@"name" : @"nope", | |
@"title" : @"nope", | |
@"payload" : @[@"nope"] | |
}]; | |
} | |
NSMutableDictionary *dItemDescription = [[self dExtract:@"WEB_LONGTEXT_comp" type:@"contentPlain"] mutableCopy]; | |
if (dItemDescription) { | |
[dItemDescription setObject:@"__Description" forKey:@"headline"]; | |
[self.foo addObject:dItemDescription]; // Beschreibung | |
} | |
NSMutableDictionary *dItemFeatures = [[self dExtract:@"FEATURES_RTF" type:@"contentPlain"] mutableCopy]; | |
if (dItemFeatures) { | |
[dItemFeatures setObject:@"__Features" forKey:@"headline"]; | |
[self.foo addObject:dItemFeatures]; // Leistungsmerkmale | |
} | |
//------------------------------------------------------------------------------------------------------------------ | |
NSArray *smzArray = _smz[@"features"]; | |
NSDictionary *fgf = smzArray[0]; | |
for (id elem in fgf[@"SMZFeatures"]) { | |
if ([@"Web_Product_Body" isEqualToString:elem[@"featureName"]]) { | |
NSArray *childFeatures = elem[@"childFeatures"]; | |
for (id childFeature in childFeatures) { | |
if ([@"TechDaten" isEqualToString:childFeature[@"featureName"]]) { | |
NSArray *techdatenArray = childFeature[@"childFeatures"]; | |
self.techArray = [self techFeaturesForRecipesArray:techdatenArray]; | |
} | |
} | |
} | |
} | |
if (self.techArray && self.techArray.count > 0) { | |
NSDictionary *dItemTechSpecs = @{ | |
@"name" : @"__Technical specifications", | |
@"title" : @"__Technical specifications", | |
@"payload" : self.techArray, | |
@"headline" : @"__Technical specifications" | |
}; | |
[self.foo addObject:dItemTechSpecs]; // Technische Daten | |
} | |
//------------------------------------------------------------------------------------------------------------------ | |
NSMutableDictionary *dItemAccessories = [[self dExtract:@"ACCESSORIES_RTF" type:@"contentPlain"]mutableCopy]; | |
[dItemAccessories setObject:@"__Accessories" forKey:@"headline"]; | |
if (dItemAccessories) | |
[self.foo addObject:dItemAccessories]; // Zubehör | |
NSMutableDictionary *dItemDeliveryScope = [[self dExtract:@"DELIVERY_SCOPE_RTF" type:@"contentPlain"]mutableCopy]; | |
[dItemDeliveryScope setObject:@"__Delivery scope" forKey:@"headline"]; | |
if (dItemDeliveryScope) | |
[self.foo addObject:dItemDeliveryScope]; // Lieferumfang | |
NSMutableDictionary *dItemDeliveryTime = [[self dExtract:@"DELIVERY_TIME" type:@"contentPlain"]mutableCopy]; | |
[dItemDeliveryTime setObject:@"__Delivery time" forKey:@"headline"]; | |
if (dItemDeliveryTime) | |
[self.foo addObject:dItemDeliveryTime]; // Lieferzeit | |
[self.tableView reloadData]; | |
} | |
- (NSDictionary *)dExtract:(NSString *)key type:(NSString *)type | |
{ | |
NSArray *featuresArray = _item[@"features"]; | |
for (NSDictionary *feature in featuresArray) { | |
if ([feature[@"name"]isEqualToString:key]) { | |
NSDictionary *result = @{ | |
@"name" : feature[@"name"], | |
@"title" : feature[@"title"], | |
@"payload" : @[feature[type]] | |
}; | |
return result; | |
} | |
} | |
return nil; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment