Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stringByAppendingString issues in objective c

Tags:

objective-c

NSString *tmpStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
xmlSms = [xmlSms stringByAppendingString:tmpStr];
NSLog(xmlSms);

I got code above but NSLog doesn't show anything... Anybody know the problem??

like image 309
BlackSoil Avatar asked Sep 04 '09 05:09

BlackSoil


1 Answers

nevermind... i figured out why. The problem is, when you want to use stringByAppendingString on a string, the string should have initial value.

Wrong example:

NSString *str1;
str1 = [str1 stringByAppendingString:@"test"];

Should be:

NSString *str1 = @"";
str1 = [str1 stringByAppendingString:@"test"];
like image 135
BlackSoil Avatar answered Nov 10 '22 18:11

BlackSoil