0

I have looked at the following resources: NSDictionary to NSArray? https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html

What I am attempting to do is insert an NSDictionary into an NSMutableArray.

The relevant code seems to be this to me:

@property (strong,nonatomic) NSMutableArray * curveList;
@property (strong,nonatomic) UIBezierPath * curPath;
@property (strong, nonatomic) UIColor * curColor;
// some code to set curPath and curColor
@{@"path":_curPath, @"color":_curColor}
//how to insert this into self.curveList???
Community
  • 1
  • 1
eckama
  • 159
  • 2
  • 3
  • 11
  • 6
    Look at the docs for `NSMutableArray`. There's a pretty obvious method for adding objects. – rmaddy Oct 08 '14 at 16:05
  • 2
    You would add an NSDictionary the same way you would add any other object. – Jsdodgers Oct 08 '14 at 16:07
  • with the setObject:forKey: method? –  Oct 08 '14 at 16:11
  • I actually pointed out that I had read that resource... I don't find them as useful as most apparently. – eckama Oct 08 '14 at 16:16
  • You didn't look very hard. I agree that the new doc format sucks, but you need to become friends with it or choose another platform to work on. (And you were actually looking at the old format that is much friendlier.) – Hot Licks Oct 08 '14 at 16:21
  • 1
    I suppose this should be down voted too then... http://stackoverflow.com/questions/1760371/how-can-we-store-into-an-nsdictionary-what-is-the-difference-between-nsdictiona I'm not sure that some people get why this site is necessary. If documentation was enough this site wouldn't actually exist as it is today. – eckama Oct 08 '14 at 16:32
  • Why there a increasing amount of people like **"Search for the answer yourself"** not even helping with Documentation Link Explanation etc. – Muhammad Asyraf Mar 20 '18 at 05:19

2 Answers2

7

you can add any object to NSMutableArray using the addObject method like this:

NSDictionary *aDic= [NSDictionary dictionaryWithObjectsAndKeys:
                              @"Carlos", @"name",
                              @"Jimenez", @"lastName", nil];

//On initialization  

NSMutableArray *aArr = [NSMutableArray arrayWithObjects:aDic,nil];

//After initialization  

NSMutableArray *aArr2 = [NSMutableArray array]; [aArr2 addObject:aDic];

Hope it helps you!

Carlos Jiménez
  • 527
  • 5
  • 15
  • 1
    thank you I will look at this and decide whether I can use it as an answer. – eckama Oct 08 '14 at 16:33
  • If you think this useful I would appreciate if you check it as correct answer :) – Carlos Jiménez Oct 08 '14 at 16:36
  • 1
    I picked yours because it was more complete as an explanation of using NSMutableArray,though @BoilingLime has the exact answer so I up voted it. A big thank you to people that understand everyone starts somewhere. – eckama Oct 08 '14 at 17:24
1
[self.curveList  addObject:@{@"path":_curPath, @"color":_curColor}];

Read Apple Class Reference

BoilingLime
  • 2,207
  • 3
  • 22
  • 37