Reputation: 125
I have a NSString with numbers e.g."1,3,6,7" and a global NSMutableArray that is initialized elsewhere.
Now to get the numbers from the string to the Array I thought something like this would work:
[myMArray arrayByAddingObjectsFromArray:([myString componentsSeparatedByString:@","])];
but it doesn't work. Can someone explain me why?
Upvotes: 0
Views: 750
Reputation: 41
In this method used to easy copy NSString to NSMutableArray:
NSMutableArray *array = array =[[NSMutableArray alloc]init];
NSString *datetime = @"(
{
content = "<p>Hallo lieber Falko,</p>\n<p>Ich bin auf der suche nach einem g\U00fcnstigen Urlaubsangebot, f\U00fcr eine Familie mit 3 ( 4;2;1) Kindern. Es soll auch nur f\U00fcr eine Woche sein. </p>\n<p>Vielen Dank f\U00fcr die mithilfe. </p>\n<p>Am besten Kreta, oder Kos. </p>\n<p>Mit freundlichen Gr\U00fc\U00dfen</p>\n";
date = "2014-05-23 22:25:44";
id = 2607;
name = Elberskirch;
parent = 0;
url = "";
}
)";
array = [[datetime propertyList]mutableCopy];
NSLog(@"%@",array);
Upvotes: 1
Reputation: 4654
The method arrayByAddingObjectsFromArray returns a new, autoreleased, NSArray
object. It looks like you're assuming it adds objects to an existing NSMutableArray
. You should use the addObjectsFromArray:(NSArray*)
method instead.
Upvotes: 4