Use the dictionary to manage the face filter and the OC dictionary to manage the face filter.

Source: Internet
Author: User

Use the dictionary to manage the face filter and the OC dictionary to manage the face filter.

Process the watermark text in the program example crayons.txt. The watermark content is about the color, and each watermark is about the color. For example: Almond # EED9C4, the first two strings are the names of the colors, and the last two strings are the hexadecimal watermark values of the colors. The following requirements are met for processing the coloring book:

1. Use the dictionary to manage all the face filters. That is, the dictionary stores multiple key-value pairs. The face Filter Name is key and the hexadecimal color value (without #) is used #) is value.

2. Retrieve all keys and sort them in ascending order.

3. Retrieve all values and sort them by sorted keys.

4. Use A new dictionary to manage colors and classify the colors. For example, "A", "B", and "C "... this dictionary contains multiple key-value pairs. The key is the 26-character mother, the value is an array, and the array delimiter stores the Color object (including name and colorValue ). You must create a Color class.

 

First, we create a Color class, Color. h declaration section:

@interface Color : NSObject{    NSString * _name;    NSString * _value;}- (instancetype)initWithName:(NSString *)name value:(NSString *)value;- (NSString *)getName;- (NSString *)getValue;@end

Color. mImplementation:

#import "Color.h"@implementation Color- (instancetype)initWithName:(NSString *)name value:(NSString *)value{    self = [super init];    if (self) {        _name = name;        _value = value;    }    return self;}- (NSString *)getName{    return _name;}- (NSString *)getValue{    return _value;}- (NSString *)description{    return [NSString stringWithFormat:@"COLOR --> %@  %@",_name,_value];}@end

In the main function, we need to meet the following requirements:

// Read the string NSString * dataString = [NSString stringWithContentsOfFile: @ "/Users/liguoxiang/Desktop/Product/OC/Lesson/HomeWork-06/HomeWork-06/crayons.txt" encoding: NSUTF8StringEncoding error: nil]; NSLog (@ "% @", dataString); // splits the string by \ n to obtain all the color strings, which are stored in the dataArray NSArray * dataArray = [dataString componentsSeparatedByString: @ "\ n"]; // create an empty variable dictionary and store the key-value pairs representing colors to NSMutableDictionary * colorDic = [NSMutableDictionary dictionaryWithCapacity: [dataArray count]; // quickly enumerate dataArray to obtain the color string for (NSString * colorString in dataArray) {// segment the colorString to obtain the color name and color value NSArray * colorComponents = [colorString componentsSeparatedByString: @ "#"]; NSString * colorName = colorComponents [0]; NSString * colorValue = colorComponents [1]; // use the color name as the key and the color value as the value, stored in the dictionary [colorDic setObject: colorValue forKey: colorName];} // After the enumeration ends, output the NSLog (@ "color dic =%@", colorDic) dictionary for color management ); // create a group dictionary NSMutableDictionary * colorGroupDic = [NSMutableDictionary dictionaryWithCapacity: 30]; // create an array and obtain all key values NSArray * colorNameArray = [colorDic allKeys]; for (int I = 0; I <[colorNameArray count]; I ++) {// retrieve the color name NSString * name = colorNameArray [I]; // obtain the value NSString * value = [colorDic objectForKey: name]; // The initial color object Color * c = [[Color alloc] initWithName: name value: value]; // groupName indicates the first letter of the color NSString * groupName = [name substringToIndex: 1]; // retrieves the array NSMutableArray * oneGroup = [colorGroupDic objectForKey: groupName]; // if the input is null if (nil = oneGroup) {// Add the color object oneGroup = [NSMutableArray arrayWithObject: c] to the array; // then add the array and group name to the dictionary [colorGroupDic setObject: oneGroup forKey: groupName];} else {// The array is not empty, indicating that the Group exists, directly add [oneGroup addObject: c] ;}} NSLog (@ "colorGroupDic =%@", colorGroupDic );

The color document (crayons.txt) used in the topic. Since the project file cannot be uploaded, I will append it to the end for readers to read. Please paste the text document created by yourself,

Almond #EED9C4Antique Brass #C88A65Apricot #FDD5B1Aquamarine #71D9E2Asparagus #7BA05BAtomic Tangerine #FF9966Banana Mania #FBE7B2Beaver #926F5BBittersweet #FE6F5EBlack #000000Blizzard Blue #A3E3EDBlue #0066FFBlue Bell #9999CCBlue Green #0095B6Blue Violet #6456B7Brick Red #C62D42Brink Pink #FB607FBrown #AF593EBurnt Orange #FF7034Burnt Sienna #E97451Cadet Blue #A9B2C3Canary #FFFF99Caribbean Green #00CC99Carnation Pink #FFA6C9Cerise #DA3287Cerulean #02A4D3Chartreuse #FF9966Chestnut #B94E48Copper #DA8A67Cornflower #93CCEACotton Candy #FFB7D5Cranberry #DB5079Dandelion #FED85DDenim #1560BDDesert Sand #EDC9AFEggplant #614051Electric Lime #CCFF00Fern #63B76CFlesh #FFCBA4Forest Green #5FA777Fuchsia #C154C1Fuzzy Wuzzy Brown #C45655Gold #E6BE8AGoldenrod #FCD667Granny Smith Apple #9DE093Gray #8B8680Green #01A368Green Yellow #F1E788Happy Ever After #6CDA37Hot Magenta #FF00CCInch Worm #B0E313Indian Red #B94E48Indigo #4F69C6Jazzberry Jam #A50B5EJungle Green #29AB87Laser Lemon #FFFF66Lavender #FBAED2Macaroni And Cheese #FFB97BMagenta #F653A6Magic Mint #AAF0D1Mahogany #CA3435Manatee #8D90A1Mango Tango #E77200Maroon #C32148Mauvelous #F091A9Melon #FEBAADMidnight Blue #003366Mountain Meadow #1AB385Mulberry #C54B8CNavy Blue #0066CCNeon Carrot #FF9933Olive Green #B5B35COrange #FF681FOrchid #E29CD2Outer Space #2D383AOutrageous Orange #FF6037Pacific Blue #009DC4Peach #FFCBA4Periwinkle #C3CDE6Pig Pink #FDD7E4Pine Green #01796FPink Flamingo #FF66FFPlum #843179Prussian Blue #003366Purple Heart #652DC1Purple Mountain's Majesty #9678B6Purple Pizzazz #FF00CCRadical Red #FF355ERaw Sienna #D27D46Razzle Dazzle Rose #FF33CCRazzmatazz #E30B5CRed #ED0A3FRed Orange #FF3F34Red Violet #BB3385Robin's Egg Blue #00CCCCRoyal Purple #6B3FA0Salmon #FF91A4Scarlet #FD0E35Screamin' Green #66FF66Sea Green #93DFB8Sepia #9E5B40Shadow #837050Shamrock #33CC99Shocking Pink #FF6FFFSilver #C9C0BBSky Blue #76D7EASpring Green #ECEBBDSunglow #FFCC33Sunset Orange #FE4C40Tan #FA9D5ATickle Me Pink #FC80A5Timberwolf #D9D6CFTorch Red #FD0E35Tropical Rain Forest #00755ETumbleweed #DEA681Turquoise Blue #6CDAE7Ultra Green #66FF66Ultra Orange #FF6037Ultra Pink #FF6FFFUltra Red #FD5B78Ultra Yellow #FFFF66Unmellow Yellow #FFFF66Violet (purple) #8359A3Violet Red #F7468AVivid Tangerine #FF9980Vivid Violet #803790White #FFFFFFWild Blue Yonder #7A89B8Wild Strawberry #FF3399Wild Watermelon #FD5B78Wisteria #C9A0DCYellow #FBE870Yellow Green #C5E17AYellow Orange #FFAE42

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.