0

I have an array like this:

(
    "ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=EF015EF6-FC98-4ACF-9092-AF7E0196A760&ext=JPG",
    "ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=6FC0C2DC-69BB-4FAD-9709-63E03182BEE1&ext=JPG",
    "ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=324E4377-0BCD-431C-8A57-535BC0FC44EB&ext=JPG"
)

And am having a hard time figuring out how to create a dictionary/mutable dictionary that will have a key of "urlRep" and also "caption" for each object in the array.

So I want my dictionary to look like this:

(
{
urlRep = 
    "ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=EF015EF6-FC98-4ACF-9092-AF7E0196A760&ext=JPG",
caption = ""
},

{
urlRep = 
    "ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=6FC0C2DC-69BB-4FAD-9709-63E03182BEE1&ext=JPG",
caption = ""
}

)

sorry if my formatting is off but that is the basic idea of what Im going for but am failing to achieve

2
  • 1
    This is pretty elementary stuff. What code do you have so far? Commented Nov 18, 2013 at 16:50
  • Note that you do not (I hope) want your dictionary to look like that, you want your array of dictionaries to look like that. Commented Nov 18, 2013 at 16:59

1 Answer 1

4

This should do the trick:

NSMutableArray *otherArray = [NSMutableArray new];
for (NSString *string in myArray)
{
    [otherArray addObject:@{@"urlRep":string, @"caption":@""}];
}

You are creating another array with a nsdictionary on every entry.

If you want to edit the caption for example for the dictionary at position 0:

[[otherArray objectAtIndex:0] setObject:@"myValue" forKey:@"caption"];

But you will have to create them as NSMutableDictionary then.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, this is what I was looking for. With this otherArray whats the best way to edit what caption is equal to?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.