Assigning values to keys in a mutable dictionary

Dhwanit Zaveri

I have a function meant for an iOS app. The NSString valueand key contain the value and key however it doesnt seem to get assign to the NSMutableDictionary data on the line [data setValue:value forKey:key]

-(NSMutableDictionary *)parseCode:(NSString *)string{
    NSArray *array = [string componentsSeparatedByString:@"||"];
    NSMutableDictionary *data;
    for(id object in array){
        NSArray *objectAndKey = [object componentsSeparatedByString:@"::"];
        NSString *key =[objectAndKey objectAtIndex:0];
        NSString *value = [objectAndKey objectAtIndex:1];
        [data setValue:value forKey:key];
        [self alertMeWithString:[data valueForKey:key]];
    }
    return data;
}
Tim

You need to initialise and allocate your NSMutableDictionary.

 NSMutableDictionary *data = [NSMutableDictionary dictionary];

Or you can explicitly make the calls using

 NSMutableDictionary *data = [[NSMutableDictionary alloc] init];

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Swap keys for values in dictionary?

分類Dev

Assign list values to dictionary keys

分類Dev

Match keys to values in dictionary in python

分類Dev

Compare keys of dictionary with values of another dictionary

分類Dev

Construct a dictionary from a list of dictionary keys, sub-keys and values

分類Dev

Filling a dataframe from a dictionary keys and values

分類Dev

retrieve values from dataframe using keys in dictionary

分類Dev

How to add multiple values to dictionary keys in Python

分類Dev

Edit nested dictionary duplicate values in same keys

分類Dev

How to sum up values of duplicate keys in a dictionary?

分類Dev

How to get dictionary keys and values if both keys are in two separated dictionaries?

分類Dev

Creating a dictionary with values identical to keys from another dictionary

分類Dev

How can I return common values of dictionary values for specific keys?

分類Dev

Python Dictionary using Lists as Values, find other Keys with same values

分類Dev

How to write an excel file which has dictionary keys as column name and dictionary values as column values?

分類Dev

Create dictionary from/with function arguments as keys and default values as value

分類Dev

Split Python dictionary into multiple keys, dividing the values equally

分類Dev

Search dictionary values and return List of keys meeting conditions

分類Dev

How to convert dictionary to dataframe when values of keys are list of list?

分類Dev

keep only keys without None values in dictionary from pandas groups

分類Dev

Make dictionary keys to be the same for common values of two different dictionaries

分類Dev

Read a JSON file and generate string keys with values in a dictionary like object

分類Dev

Converting nested dictionary to dataframe with the keys as rownames and the dictionaries in the values as columns?

分類Dev

From Pandas series, create dictionary with unique elements as keys, and their indices as values

分類Dev

Filling a dataframe from a dictionary keys and values: efficient way

分類Dev

add keys and values to a dictionary from multiple objects by for loop

分類Dev

(More) nested dictionary comprehensions: How to switch inner values to keys?

分類Dev

How to convert a dictionary to a list of keys, with repeat counts given by the values?

分類Dev

Python: Creating a new dictionary while switching keys and values

Related 関連記事

  1. 1

    Swap keys for values in dictionary?

  2. 2

    Assign list values to dictionary keys

  3. 3

    Match keys to values in dictionary in python

  4. 4

    Compare keys of dictionary with values of another dictionary

  5. 5

    Construct a dictionary from a list of dictionary keys, sub-keys and values

  6. 6

    Filling a dataframe from a dictionary keys and values

  7. 7

    retrieve values from dataframe using keys in dictionary

  8. 8

    How to add multiple values to dictionary keys in Python

  9. 9

    Edit nested dictionary duplicate values in same keys

  10. 10

    How to sum up values of duplicate keys in a dictionary?

  11. 11

    How to get dictionary keys and values if both keys are in two separated dictionaries?

  12. 12

    Creating a dictionary with values identical to keys from another dictionary

  13. 13

    How can I return common values of dictionary values for specific keys?

  14. 14

    Python Dictionary using Lists as Values, find other Keys with same values

  15. 15

    How to write an excel file which has dictionary keys as column name and dictionary values as column values?

  16. 16

    Create dictionary from/with function arguments as keys and default values as value

  17. 17

    Split Python dictionary into multiple keys, dividing the values equally

  18. 18

    Search dictionary values and return List of keys meeting conditions

  19. 19

    How to convert dictionary to dataframe when values of keys are list of list?

  20. 20

    keep only keys without None values in dictionary from pandas groups

  21. 21

    Make dictionary keys to be the same for common values of two different dictionaries

  22. 22

    Read a JSON file and generate string keys with values in a dictionary like object

  23. 23

    Converting nested dictionary to dataframe with the keys as rownames and the dictionaries in the values as columns?

  24. 24

    From Pandas series, create dictionary with unique elements as keys, and their indices as values

  25. 25

    Filling a dataframe from a dictionary keys and values: efficient way

  26. 26

    add keys and values to a dictionary from multiple objects by for loop

  27. 27

    (More) nested dictionary comprehensions: How to switch inner values to keys?

  28. 28

    How to convert a dictionary to a list of keys, with repeat counts given by the values?

  29. 29

    Python: Creating a new dictionary while switching keys and values

ホットタグ

アーカイブ