views:

55

answers:

2

I have in the .h file :

NSString *dataHML; 
NSString *dataHML2;
NSString *dataHML3;
NSString *dataHML4;
NSString *dataHML5;
NSString *dataHML6;
NSString *dataHMLtotal;

in the .m file i merge them with :

NSString *dataHtmlTotal = [NSString stringWithFormat:@"%@%@%@%@%@%@", dataHtml, dataHtml2, dataHtml3, dataHtml4,dataHtml5,dataHtml6];

But unfortunately it crashes at some point because of this. Could anyone give me a other solution and post it please, because i already tried nsuserdefault or a nsarray, but without i coudn't get it working :(

A: 

Please make sure your strings are all allocated and initialized (neither points of which you mention in your question.) If you do not do so then you run the risk of manipulating data at the location of the garbage pointers, and your application will very likely crash.

fbrereto
@dreamlex :I have red online tutorials, and my code is quite long to post all of it, thats is the reason why i placed a small peace of it with has the problem.If i could fix this problem myself i wouldn't place my problem here ofc. :) And i agree it is dataHMLTotal instead of dataHtmlTotal, but the problem stays that it crashes.
Ruiter
A: 

If you really do have 6 variables numerically named like that, you could be better off with an array.

NSMutableArray *dataHMLStrings = [NSMutableArray array];

[dataHMLStrings addObject:@"String1"];
[dataHMLStrings addObject:@"String2"];
            .
            .
            .
[dataHMLStrings addObject:@"String100"]; // or however many you have.

NSString *dataHMLTotal = [dataHMLStrings componentsJoinedByString:@""];

You can give the componentsJoinedByString: method a different string (I passed an empty string here because you didn't want anything to appear between each dataHML string).

dreamlax
Thanks, now this is a very usefull tip :D
Ruiter